• Post Reply Bookmark Topic Watch Topic
  • New Topic

looping  RSS feed

 
ben riches
Ranch Hand
Posts: 126
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hello i hope someone can help me i have this code which is looping though the vector and picking out the first word of a line then it loops though and picks out every 10th word so i get the first word of each line. but i want another loop so i can print out the second word of each line and the third and so on.
any suggestions would be grateful
thanks ben

(edited by Cindy to format code . . . pleeeeeeease try to do it yourself next time)
[ November 20, 2002: Message edited by: Cindy Glass ]
 
Pete Lyons
Ranch Hand
Posts: 109
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The code would be different (simpler) if you knew for sure each line would contain the same number of words. Is that the case? What you might do is read the file line by line and token by token, and push each word into a List of Lists (a 2-dimensional ArrayList), and then you would have random access to any arbitrary word of any arbitrary line. You'd basically have 2 nested while loops, 1 for the BufferedReader.readLine(), and one for StringTokenizer.hasMoreTakens().
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!