How to implement a sequential tree traversal in Java? (TreeSet)

Closed due to the fact that the essence of the issue is incomprehensible to the participants vp_arth , Mikhail Vaysman , rjhdby , Yuri , Harry March 18 '17 at 10:12 .

Try to write more detailed questions. To get an answer, explain what exactly you see the problem, how to reproduce it, what you want to get as a result, etc. Give an example that clearly demonstrates the problem. If the question can be reformulated according to the rules set out in the certificate , edit it .

  • 2
    And what the iterator does not suit you? - JVic
  • the task is ... "Bypass type: sequential" - Aleksandr
  • What do you mean by sequential? The tree stores data in sorted form. You can walk through it either with an iterator or for each - JVic

1 answer 1

You were correctly told about the iterators. Set (TreeSet) sets implement the basic Collection interface, which in turn implements Iterable. This means that you can iterate for each

 Set<String> ts = new TreeSet<>(); ts.add("s1"); ts.add("s0"); for (String s : ts) { System.out.println(s); }