• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Sorting a String into a TreeSet....

 
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Ranch Hand
Posts: 84
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
"iterator" should be "Iterator" - all class names traditionally begin with a capital letter and Iterator is a class.
 
reply
    Bookmark Topic Watch Topic
  • New Topic