Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 170
  • 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

Featured Post

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

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