Jump to content

Java LinkedList, one question please

- - - - -

  • Please log in to reply
2 replies to this topic

#1
toto_7

toto_7

    Programming Professional

  • Members
  • PipPipPipPipPip
  • 295 posts
I would like to ask, if there is a way to print any other element from a LinkedList instead of first and last.
My idea:
I have created a button, and when click on it, i would like to show on textArea the first element, if clicked again the second and etc...

#2
lethalwire

lethalwire

    while(false){ ... }

  • Members
  • PipPipPipPipPipPipPip
  • 748 posts
  • Programming Language:Java, PHP
  • Learning:Java, PHP
If you're using Sun's implementation of a LinkedList you should be able to use the get(int index) method.

If you're using your own implementation you'll have to either add a method to your LinkedList or something else...

#3
PhillipKessels

PhillipKessels

    Newbie

  • Members
  • Pip
  • 8 posts
you could have a look how sun implemented it in their version or simply implement it by a copy of the list (copy the list, remove til n+1 element, then refill ur original list)....

ask me if something remains unclear to u and ill try to explain in more detail ;-)




1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users