Home | Ajax | BioInformatics | Dojo | EAI | EJB | Hibernate | J2ME | Java | Java Glossary | Java Servlets | JavaScript | Jboss | JDBC | JDO | Jmeter | JSF | JSP | JUnit | Maven | MySQL | Spring Framework | SQL | Struts | Technology | WAP | Web Services | XML


 
  
 
Programming Tutorials: Ajax | Articles | JSP | Bioinformatics | Database | Free Books | Hibernate | J2EE | J2ME | Java | JavaScript | JDBC | JMS | Linux | MS Technology | PHP | RMI | Web-Services | Servlets | Struts | UML
 

 
Facing Programming Problem?
Ask Questions?, Browse Latest Questions, Question-Answer Guidelines
Java
  JDO Tutorials
  EAI Articles
  Struts Tutorials
  Java Tutorials
  Java Certification
  Java Applet
Questions
Comments

Link List Example in Java

                         

In this example, we are going to show the use of java.util.LinkedList class. You will be creating an object of link list class and performing various operation like adding and removing object.  

This class extends AbstractSequentialList and implements List, Cloneable, Serializable. It permits all elements including null. LinkedList class provides  methods get, insert and remove  an element at the beginning and end of the list.

In this example we are using six methods of LinkedList class.

add(Object o): Appends the specified element to the end of this list. It returns a boolean value.

size(): Returns the number of elements in this list.

addFirst(Object o): Inserts the given element at the beginning of this list.

addLast(Object o): Inserts the given element at the last of this list.

add(int index,Object o): Insert the specified element at the specified position in this list. It throws IndexOutOfBoundsException if index is out of range. 

remove(int index): Remove the element at the specified position in this list. It returns the element that was removed from the list. It throws IndexOutOfBoundsException if index is out of range. 

The code of the program is given below:

import java.util.*;

public class LinkedListDemo{
  public static void main(String[] args){
    LinkedList link=new LinkedList();
    link.add("a");
    link.add("b");
    link.add(new Integer(10));
    System.out.println("The contents of array is" + link);
    System.out.println("The size of an linkedlist is" + link.size());
    
    link.addFirst(new Integer(20));
    System.out.println("The contents of array is" + link);
    System.out.println("The size of an linkedlist is" + link.size());

    link.addLast("c");
    System.out.println("The contents of array is" + link);
    System.out.println("The size of an linkedlist is" + link.size());

    link.add(2,"j");
    System.out.println("The contents of array is" + link);
    System.out.println("The size of an linkedlist is" + link.size());

    link.add(1,"t");
    System.out.println("The contents of array is" + link);
    System.out.println("The size of an linkedlist is" + link.size());

    link.remove(3);
    System.out.println("The contents of array is" + link);
    System.out.println("The size of an linkedlist is" + link.size());
  }
}

Output of the program will be like this:

The contents of array is[a, b, 10]
The size of an linkedlist is3
The contents of array is[20, a, b, 10]
The size of an linkedlist is4
The contents of array is[20, a, b, 10, c]
The size of an linkedlist is5
The contents of array is[20, a, j, b, 10, c]
The size of an linkedlist is6
The contents of array is[20, t, a, j, b, 10, c]
The size of an linkedlist is7
The contents of array is[20, t, a, b, 10, c]
The size of an linkedlist is6

Download this example.

                         

Leave your comment:

Name:

Email:

URL:

Title:

Comments:


Enter Code:

Audio Version
Reload Image
 

Note: Emails will not be visible or used in any way, and are not required. Please keep comments relevant. Any content deemed inappropriate or offensive may be edited and/or deleted.

No HTML code is allowed. Line breaks will be converted automatically. URLs will be auto-linked. Please use BBCode to format your text.

Add This Tutorial To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 

Current Comments

2 comments so far (
post your own) View All Comments Latest 10 Comments:

very helpful!! thank you!

Posted by Kanan on Tuesday, 10.7.08 @ 09:48am | #80933

Your attempt is very good. But this illustration is not very good. Because of there was not really good code for above title. When enetered the code of the any program, please try to enter the meaningfull code or whatever.

Posted by tharaka deeal godakumbura on Thursday, 09.18.08 @ 10:47am | #80256

Latest Searches:
Flex TreeGrid
java program to find s
Date Examples java
binary to hexadecimal
myfaces tomahawk
sqlserver2000
Installing Sun JDK on
what is rfc ?
struts 1 date picker e
midlet inbox example
modity data in text fi
in mysql how to store
Photoshop Drawing Cart
JDBC with Mysql in Ecl
form bean
collections interview
web.xml file
Matrix Example in Java
breakั?�??????ั?
program to find greate
WHERE Statement in SQL
mdb
create a tree to be di
java cancel button
find out factors of nu
passing value from ser
Struts1.1 example down
bubble sort
rfc
JSP in error page
Display image on JSP p
JScrollPane
Date
how to get the time di
DB2
download package com.s
log4j/
java program to check
conversion of decimal
array java
api struts
linked list and GUI
Designing Star sign sy
SwingWorker
Hibernate Min() Functi
java code for circula
breakâ???â?¬â?¤????â??
jsp table
Java EJB Struts Hibern
list box from database
text color
jstl list size
placeholder
create file folder
drill down
Tomahawk commandLink t
jpanel
struts2 checkbox
retrieving data from h
Html tag inside out im
regularexpression
jsf validator
hibernate findall
Icon
Telephony
code to add and retriv
Flash Navigation Drop
diffreence between ser
how to configure msacc
s:If Struts2
access bean properties
'string variable in sw
Reading File into Byte
jsf node set href
jsp bean get property
javascript connect db
sun.jdbc.odbc.JdbcOdbc
Applet event button
Insert Data into Datab
JTree Open Icon
Java String toLowerCase Example
Java String toCharArray Example
Java String substring Example
Java String indexOf Example
Java String startsWith Example
Java String hashCode Example
Java String matches Example
Java String length Example
Java String lastIndexOf Example
Java String isEmpty Example
Java String equalsIgnoreCase Example
Java String equals Example
Java String endsWith Example
Java String copyValueOf Example
Java String contentEquals Example
  EAI Articles
  Java Certification
Tell A Friend
Your Friend Name
Search Tutorials

 

 
 
Browse all Java Tutorials
Java JSP Struts Servlets Hibernate XML
Ajax JDBC EJB MySQL JavaScript JSF
Maven2 Tutorial JEE5 Tutorial Java Threading Tutorial Photoshop Tutorials Linux Technology
Technology Revolutions Eclipse Spring Tutorial Bioinformatics Tutorials Tools SQL
 

Home | JSP | EJB | JDBC | Java Servlets | WAP  | Free JSP Hosting  | Search Engine | News Archive | Jboss 3.0 tutorial | Free Linux CD's | Forum | Blogs

About Us | Advertising On RoseIndia.net  | Site Map

India News

Indian Software Development Company | iPhone Development Company in India | Java Training Delhi | Java Training at Noida |

Send your comments, Suggestions or Queries regarding this site at roseindia_net@yahoo.com.

Copyright © 2008. All rights reserved.