Win a copy of Kotlin in Action this week in the Kotlin forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

cannot resolve iterator???confusing!!!  RSS feed

 
Selecta Zhangy
Greenhorn
Posts: 16
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
i was trying to write a music search engine, and i used iterator in order to make that...but why it cant resolve the one, resolve iterator???why???

thamks

 
marc weber
Sheriff
Posts: 11343
Java Mac Safari
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Welcome to JavaRanch!

String does not have an iterator() method.
 
Christophe Verré
Sheriff
Posts: 14691
16
Eclipse IDE Ubuntu VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator


Those are strings. There's no iterator() method in the String class.
 
Selecta Zhangy
Greenhorn
Posts: 16
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
oh you mean they must be numbers(int)...

well, that sucks for sure. so what method can be used for searching name(String)?

thanks a lot!!!
 
marc weber
Sheriff
Posts: 11343
Java Mac Safari
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Selecta Zhangy:
oh you mean they must be numbers(int)...

No. An iterator is basically used for iterating through a collection of objects. For example, if you have an ArrayList of Strings, then you could use an iterator to iterate through that list of Strings.

Originally posted by Selecta Zhangy:
...so what method can be used for searching name(String)? ...

What exactly are you trying to do here?
 
Selecta Zhangy
Greenhorn
Posts: 16
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by marc weber:

What exactly are you trying to do here?


im trying to write a music search engine... so when i enter the title of the music, the correct the music and its deatails will be shown after...
 
Mingwei Jiang
Ranch Hand
Posts: 63
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
If you'd like to use an ArrayList. You must iterate through the array list. For example:
 
marc weber
Sheriff
Posts: 11343
Java Mac Safari
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Selecta Zhangy:
...im trying to write a music search engine... so when i enter the title of the music, the correct the music and its deatails will be shown after...

Yes, but I'm confused by the logic of your code. You have an ArrayList of MusicItems...

ArrayList items = musiccatalog.getMusicItems();

So it seems that you would iterate through these items (using an Iterator provided by the list) and call something like getTitle() or getArtist() on each MusicItem in order to do your comparison.
 
Christophe Verré
Sheriff
Posts: 14691
16
Eclipse IDE Ubuntu VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
An intro about Iterators may help too :
http://java.sun.com/docs/books/tutorial/collections/interfaces/collection.html
 
Selecta Zhangy
Greenhorn
Posts: 16
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
still cant work it out, struggling

seems this one cant work well either:

 
Jesper de Jong
Java Cowboy
Sheriff
Posts: 16028
87
Android IntelliJ IDE Java Scala Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You're not using Iterator or looping through the list in any way in your last piece of code.

First, think about what the program has to do exactly, step by step. Then translate the idea into lines of Java code. For example:

- You have a list of MusicItem objects
- Make a loop that goes over every item of the list (you'll be using Iterator here)
- Inside the loop, for each music item check if the title matches what you're looking for
- If yes: you've found it, print out some message
- If no: do nothing, continue the loop
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!