• Post Reply Bookmark Topic Watch Topic
  • New Topic

Sorting a String into a TreeSet....  RSS feed

 
Chris Parkinson
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi, I'm having a problem with the following code:
public class tokenizerTest
{
public static void main(String args[])
{
String str = new String("AbC,DeFg,ZxHn");
String theStringLower = str.toLowerCase();
StringTokenizer tokens = new StringTokenizer(theStringLower,",");
Set sortedWords = new TreeSet();


while (tokens.hasMoreTokens())
{
sortedWords.add(tokens.nextToken());
}

for (iterator iter = sortedWords.iterator(); iter.hasNext()
System.out.println(iter.next());
}
}
I want to sort the string alphabetically using a TreeSet and then print this as output. When compiling the error points to the iterator part. Any help will be greatly received.
Thanks
 
Carlos Failde
Ranch Hand
Posts: 84
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
"iterator" should be "Iterator" - all class names traditionally begin with a capital letter and Iterator is a class.
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!