/* * LinkedList.java * * Created on January 10, 2008, 8:51 PM * * To change this template, choose Tools | Template Manager * and open the template in the editor. */package linkedlist;import java.util.List;import java.util.LinkedList;import java.util.Iterator;import java.util.ListIterator;import java.util.Collections;import java.util.Random;/** * * @author Sayed */public class LinkedListTest { /** Creates a new instance of LinkedList */ public LinkedListTest() { } /** *Example operations using linked lists */ public void linkedListOperation(){ final int MAX = 10; int counter = 0; //create two linked lists List listA = new LinkedList(); List listB = new LinkedList(); //store data in the linked list A for (int i = 0; i < MAX; i++) { System.out.println(" - Storing Integer(" + i + ")"); listA.add(new Integer(i)); } //print data from the linked list using iterator Iterator it = listA.iterator(); while (it.hasNext()) { System.out.println(it.next()); } //print data from the linked list using listIterator. counter = 0; ListIterator liIt = listA.listIterator(); while (liIt.hasNext()) { System.out.println("Element [" + counter + "] = " + liIt.next()); System.out.println(" - hasPrevious = " + liIt.hasPrevious()); System.out.println(" - hasNext = " + liIt.hasNext()); System.out.println(" - previousIndex = " + liIt.previousIndex()); System.out.println(" - nextIndex = " + liIt.nextIndex()); System.out.println(); counter++; } //retrieve data from the linked list using index for (int j=0; j < listA.size(); j++) { System.out.println("[" + j + "] - " + listA.get(j)); } //find the location of an element int locationIndex = listA.indexOf("5"); System.out.println("Index location of the String "5"" is: "" + locationIndex); //find the first and the last location of an element System.out.println(""First occurance search for String ""5"". Index = "" + listA.indexOf(""5"")); System.out.println(""Last Index search for String ""5"". Index = "" + listA.lastIndexOf(""5"")); //create a sublist from the list List listSub = listA.subList(10
From: http://sitestree.com/?p=4788
Categories:Java Short Notes
Tags:
Post Data:2013-04-04 09:12:30
Shop Online: https://www.ShopForSoul.com/
(Big Data, Cloud, Security, Machine Learning): Courses: http://Training.SitesTree.com
In Bengali: http://Bangla.SaLearningSchool.com
http://SitesTree.com
8112223 Canada Inc./JustEtc: http://JustEtc.net (Software/Web/Mobile/Big-Data/Machine Learning)
Shop Online: https://www.ShopForSoul.com/
Medium: https://medium.com/@SayedAhmedCanada