Created
February 25, 2022 00:37
-
-
Save mueschm/3cb9580b0b1f0ca079bcc76adc3e861a to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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