I am trying to sort 3 strings alphabetically using the compareTo method in java without using arrays.
Is the fastest way to do this by setting up 6 compare statements and sorting by least to greatest or is there any easier way? Thanks!
I am trying to sort 3 strings alphabetically using the compareTo method in java without using arrays.
Is the fastest way to do this by setting up 6 compare statements and sorting by least to greatest or is there any easier way? Thanks!
put it into TreeSet
.
TreeSet<String> t = new TreeSet<>();
t.add("stack");
t.add("over");
t.add("flow");
System.out.println(t);
OutPut:
[flow, over, stack]