Creating a List

// Create the list List list = new LinkedList(); // Doubly-linked list list = new ArrayList(); // List implemented as growable array // Append an element to the list list.add("a"); // Insert an element at the head of the list list.add(0, "b"); // Get the number of elements in the list int size = list.size(); // 2 // Retrieving the element at the end of the list Object element = list.get(list.size()-1); // a // Retrieving the element at the head of the list element = list.get(0); // b // Remove the first occurrence of an element boolean b = list.remove("b"); // true b = list.remove("b"); // false // Remove the element at a particular index element = list.remove(0); // a

Comments

10 Jan 2010 - 1:31pm by Anonymous (not verified)

good

7 Mar 2010 - 6:39am by Anonymous (not verified)

can you give some list of program in java

28 Mar 2010 - 8:10am by Anonymous (not verified)

very easy

6 Apr 2010 - 4:08am by Anonymous (not verified)

what do you have to import to use list

25 Apr 2010 - 1:12pm by Anonymous (not verified)

java.util.List;
You should use an IDE such as Eclipse though. (it will automatically tell you)

17 May 2010 - 6:30am by Anonymous (not verified)

i need...java funtion example pls give me ..thx

3 Sep 2010 - 12:38am by tudor watches (not verified)

A man named zenith el primero Fadel is opening a pickle Dior costume jewelry shop in another building. It's watches michele one of the safest places Nike for children in Baghdad, he said.

Post a comment

More information about formatting options

CAPTCHA
This question is for testing whether you are a human visitor and to prevent automated spam submissions.
Image CAPTCHA
Enter the characters shown in the image. Ignore spaces and be careful about upper and lower case.