0

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!

Ryan
  • 57
  • 1
  • 5
  • 15

1 Answers1

0

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]
Trying
  • 14,004
  • 9
  • 70
  • 110