Skip to content

Instantly share code, notes, and snippets.

@mueschm
Created February 25, 2022 00:37
Show Gist options
  • Save mueschm/3cb9580b0b1f0ca079bcc76adc3e861a to your computer and use it in GitHub Desktop.
Save mueschm/3cb9580b0b1f0ca079bcc76adc3e861a to your computer and use it in GitHub Desktop.
interface MyList<T> {
void add(T element);
T get(int index);
}
class MyArrayList<T> implements MyList<T> {
private Object[] elements;
private int index;
MyArrayList() {
elements = new Object[10];
index = 0;
}
public void add(T element) {
elements[index++] = element;
}
public T get(int index) {
return (T)elements[index];
}
}
class HelloWorld {
public static void main(String[] args) {
MyArrayList<String> list = new MyArrayList<>();
list.add("HELLO");
System.out.println(list.get(0));
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment