I am trying to sort an ArrayList of strings. So far I have tried using ArrayList.sort
but I am note sure how to use it properly.
My class looks like this:
ArrayList<String> arraylist = new ArrayList<>();
String value,value1,value2;
value="String1";
value1="String2";
value3="String3";
arraylist.add(value);
arraylist.add(value1);
arraylist.add(value2);
I have no idea how to sort this one. Last time when I was using ArrayList of custom objects like
ArrayList<myObject> = new ArrayList<>();
I implemented Comparable
interface, then I overrode the compareTo
method in myObject class and everything was...easier.
How do I sort with ArrayList using just simple Strings?
@Edit
Trying few things on my own, I've used arraylist.sort(null)
and somehow it worked like it was supposed to. No more help is needed, thank you guys.