What is the best case and worst case time complexity for my method below?
I know ArrayList.add() is of O(1) time complexity but not sure about loaded.stream().distinct().collect(Collectors.toList());
public static int countUnique(WordStream words) {
ArrayList<String> loaded = new ArrayList<String>();
ArrayList<String> empty = new ArrayList<String>();
// Fill loaded with WordStream words
for (String i : words) {
loaded.add(i);
}
empty = (ArrayList<String>) loaded.stream().distinct().collect(Collectors.toList());
return empty.size();
}