Reputation: 762
I know that The Treeset Sort the input automatically but don't accept duplicates.Is there any class Collection in java that allows Duplicate values or objects and Sort the given Input
Upvotes: 1
Views: 171
Reputation: 7899
User List Implementation and sort them using Collection.sort()
List<String> list=new ArrayList<String>();
list.add("A");
list.add("C");
list.add("A");
list.add("B");
list.add("A");
System.out.println(list);
Collections.sort(list);
System.out.println(list);
But if you are using you object in collection then Implement Comparable
interface and override compare(Object obj,Object obj1)
method.
Otherwise you can write your Comparator
then pass it to sort
method.
Upvotes: 0