• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 175
  • Last Modified:

linked list

how to used linked list in java.... get the item and display it 1 by 1..... please provide  exmple...
0
Jacqueline_toh
Asked:
Jacqueline_toh
  • 2
  • 2
1 Solution
 
mmuruganandamCommented:
import java.text.DecimalFormat;
import java.util.Iterator;
import java.util.LinkedList;

public class Test
{
      public static void main(String[] args)
      {
            LinkedList list = new LinkedList();
            list.add("hello 1");
            list.add("hello 2");
            list.add("hello 3");
            list.add("hello 4");
            
            for (int i = 0; i < list.size(); i++)
            {
                  System.out.println((String)list.get(i));
            }
            
            Iterator iter = list.iterator();
            while (iter.hasNext())
            {
                  System.out.println((String)iter.next());
            }
      }
}


You can add this way.
I have provided two types of printing.


Regards,
Muruga
0
 
Mayank SAssociate Director - Product EngineeringCommented:
Muruga, that goes slightly against the policies for homework. Anyway, there are some examples here as well:

http://www.javaalmanac.com/egs/java.util/coll_Lists.html
0
 
mmuruganandamCommented:
mayankeagle,  you are some what right.  But his words doesn't seems like that.  So I have provided.
0
 
Mayank SAssociate Director - Product EngineeringCommented:
That is the problem with such short-worded questions. Anyway ;-) !
0
 
sciuriwareCommented:
Tip: the middle part of the question reveals it: teacher's words!

;JOOP!
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Introducing Cloud Class® training courses

Tech changes fast. You can learn faster. That’s why we’re bringing professional training courses to Experts Exchange. With a subscription, you can access all the Cloud Class® courses to expand your education, prep for certifications, and get top-notch instructions.

  • 2
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now