Reputation: 63
I am having trouble printing out individual Strings from Interable object. I have this given function prefixMatch(String someword) that returns Iterable (that keeps a LinkedList of Strings, I think). I have tried turning it into a list but it wont work. Dose anyone know how to get the Strings out of it one by one?
tst is a Ternary search tree
Iterable<String> words = tst.prefixMatch(word);
Upvotes: 6
Views: 20899
Reputation: 5986
The java 8 way, using forEach
:
words.forEach(word-> System.out.println(word));
Upvotes: 2
Reputation: 4870
I think this will help you, here i am using Iterable.
TreeSet treeSet = new TreeSet<String>();
treeSet.add("A");
treeSet.add("B");
Iterable<String> it = treeSet;
Iterator iterator = it.iterator();
while (iterator.hasNext()) {
System.out.println(iterator.next());
}
Upvotes: 0
Reputation: 93167
If it's Iterable
you can do an extended for on it.
Iterable<String> iterable;
for(String s : iterable){
//Do whatever you want
}
Resources:
Related topics:
Upvotes: 12