Time Complexity for Java ArrayList

The best resource is straight from the official API: The size, isEmpty, get, set, iterator, and listIterator operations run in constant time. The add operation runs in amortized constant time, that is, adding n elements requires O(n) time. All of the other operations run in linear time (roughly speaking). The constant factor is low compared … Read more

How to make a separated copy of an ArrayList? [duplicate]

Yes that’s correct – You need to implement clone() (or another suitable mechanism for copying your object, as clone() is considered “broken” by many programmers). Your clone() method should perform a deep copy of all mutable fields within your object. That way, modifications to the cloned object will not affect the original. In your example … Read more

Merge 3 arraylist to one

Use ArrayList.addAll(). Something like this should work (assuming lists contain String objects; you should change accordingly). List<String> combined = new ArrayList<String>(); combined.addAll(firstArrayList); combined.addAll(secondArrayList); combined.addAll(thirdArrayList); Update I can see by your comments that you may actually be trying to create a 2D list. If so, code such as the following should work: List<List<String>> combined2d = new … Read more