Hmm. don't seem to work

On Jun 30, 9:22 pm, "* ^ *" <[email protected]> wrote:
> On Jul 1, 2:56 am, Maul <[email protected]> wrote:
>
>
>
> > 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?
>
> Just a guess. Assign next() to an object. For example:
> Object elem=li.next();
> if(elem.getClass().getName().equals("java.lang.String"){ ..

--~--~---------~--~----~------------~-------~--~----~
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
-~----------~----~----~----~------~----~------~--~---

Reply via email to