I have a CustomList which does everything as needed until I encountered that code like String.join(" ", list) or list.toArray(String[]::new) doesn't work with my CustomList but works with ArrayList. What am I doing wrong?
CustomList adds and removes every element in pairs.
class CustomList implements List<String> {
private List<String> list;
public CustomList() {
list = new ArrayList<String>();
}
//implemented overridden methods
}
String.join(" ", list) throws a NullPointerException.
list.toArray(String[]::new) returns null.
public <T> T[] toArray(T[] a) {
list.toArray(a);
return a;
}
public Iterator<String> iterator() {
return list.iterator();
}
list.toArray(String[]::new)doesn't compile for me. Perhaps, the way you use the class is wrong.I implemented the methods:
Then I tested the
CustomList:Output: