• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Stringtokenizer values.

 
Charles Jefferson
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello. I have been lurking around here getting tips and advice for quite some time: it's greatly appreciated. I am, however, stumped, and need some help using Stringtokenizer. I will comment parts of code to keep it confidential, but what is posted should explain:



In essence, why is songtitle[] not printing?
 
Larry Frissell
Ranch Hand
Posts: 82
2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I suspect you are getting a StringIndexOutOfBoundsException, Try putting a System.out.println(" exception" ); in your catch block and see what happens.
 
Campbell Ritchie
Sheriff
Posts: 48652
56
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Welcome to JavaRanch

Have you been told to use StringTokenizer? It is described here as legacy code and users are "discouraged" from using it in new code.

You can get individual lines from a text file by various techniques; I think the Scanner#nextLine() method might be the simplest. Then you can use the java.lang.String#split method to separate it into words.
You can do all sorts of things with those words, even putting them into a java.util.Set<String> which has a contains method.
 
Charles Jefferson
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I am not required to do anything; this is a personal project I'm working on. The problem I had was finding a way to do this. I am currently taking a JAVA class and they are fans of using the Princeton Standard Libraries to try to "simplify" things...meanwhile, it's not convenient when trying to do slightly more difficult things.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic