Arraylist

A simple collection data type found in some languages / platforms (such as in Java or .NET)

Treeset

A Java set implementation sorting its items upon insertion; provided by JRE/JDK.



Arraylist later mind

Example

"So if you re mainly retrieving and don t sort often arraylist is the better choice;if you sort often but dont retrieve that much treeset would be a better choice"

from question  

Is it faster to add to a collection then sort it, or add to a sorted collection?

"Now let s say you ve implemented your list with an arraylist;later you change your mind deciding that a treeset is better"

from question  

Java cannot find symbol with linked list

Others

Example

It would be easiest to use a sortedset arraylist does not have sorting built in by default;treeset is the concrete implementation and then pass a custom comparator which just delegates to the date object

from question  

Sorting ArrayList of custom objects by one of it's members

Then we could use treeset to sort an array faster than the method made specifically to sort it the saving gotten from not having to insert into the arraylist is fairly small;if this were consistently true java developers would simply replace that method with treeset wouldn t they

from question  

Optimize code with ArrayList or TreeSet?

So arraylist and sort is more effective than treeset

from question  

TreeSet vs ArrayList and sort

If you only sort once then the arraylist is an obvious winner;the treeset is better if you add or remove items often as sorting a list again and again would be slow

from question  

Is it better to use a TreeSet or ArrayList when using a custom comparator

If you don t add an comparator the treeset implicitly expects the arraylist to realize the comparable-interface which it does not do;the treeset doesn t know how to sort the arraylists because there is no natural ordering for lists

from question  

Can I sort ArrayList of ArrayList simply by using TreeSet?

Back to Home
Data comes from Stack Exchange with CC-BY-SA-4.0