The following code is from "Java Collection Framework" tutorial from
JavaIntro, modified to want I wanna do:)
What I wanna find out is how you would look for an object of a
specific element in an ListIterator. Let's say I want to find out if
the next() element in ListIterator is an instance of the String Class
and do something if this is true. What I have tried is
// Create ListIterator and iterate entries in it
ListIterator li = al.listIterator();
while (li.hasNext())
If(li.next().getClass().getName() == "java.lang.String")
System.out.println("From ListIterator = " + li.next()
+ " is a String object");
else
System.out.println("From ListIterator = " + li.next
());
The problem with the above code is that the next() method seems to
move the cursor of the ListIterator one step forward and therebye
skipping an element because there is a next() method in the if(....)
and in the println(), how do I sort this?
--~--~---------~--~----~------------~-------~--~----~
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/javaprogrammingwithpassion?hl=en
-~----------~----~----~----~------~----~------~--~---