Example usage for java.util LinkedList LinkedList

List of usage examples for java.util LinkedList LinkedList

Introduction

In this page you can find the example usage for java.util LinkedList LinkedList.

Prototype

public LinkedList() 

Source Link

Document

Constructs an empty list.

Usage

From source file:Main.java

public static void main(String[] args) {
    // create a LinkedList
    LinkedList<String> list = new LinkedList<String>();

    // add some elements
    list.add("Hello");
    list.add("from java2s.com");
    list.add("10");

    // print the list
    System.out.println("LinkedList:" + list);

    // set Iterator as descending
    Iterator x = list.descendingIterator();

    // print list with descending order
    while (x.hasNext()) {
        System.out.println(x.next());
    }//from  w w w .  jav  a2 s. c om
}

From source file:Main.java

public static void main(String[] argv) {

    List<String> sortedList = new LinkedList<String>();
    sortedList.addAll(Arrays.asList(new String[] { "a", "b", "c", "d" }));

    int index = Collections.binarySearch(sortedList, "c");
    System.out.println(index);//  w  w w  .  ja  v a  2 s.co  m
    index = Collections.binarySearch(sortedList, "e");
    System.out.println(index);
}

From source file:Main.java

public static void main(String[] args) {

    // create a LinkedList
    LinkedList<String> list = new LinkedList<String>();

    // add some elements
    list.add("Hello");
    list.add("from java2s.com");
    list.add("10");

    // print the list
    System.out.println("LinkedList:" + list);

    // set Iterator at specified index
    Iterator x = list.listIterator(1);

    // print list with the iterator
    while (x.hasNext()) {
        System.out.println(x.next());
    }//from  w ww  . jav  a2 s.  com
}

From source file:Main.java

public static void main(String args[]) {

    List<Character> ll = new LinkedList<Character>();

    for (char n = 'A'; n <= 'F'; n++)
        ll.add(n);/*from   w  ww.  j a  va  2  s .c o m*/

    System.out.println("Here is the original list: ");
    for (Character x : ll)
        System.out.print(x + " ");
    Collections.reverse(ll);

    System.out.println("Here is the reversed list: ");
    for (Character x : ll)
        System.out.print(x + " ");
    Collections.rotate(ll, 2);

    for (Character x : ll)
        System.out.print(x + " ");

    Collections.shuffle(ll);

    System.out.println("Here is the randomized list:");
    for (Character x : ll)
        System.out.print(x + " ");
}

From source file:Main.java

public static void main(String[] argv) {

    List<String> sortedList = new LinkedList<String>();
    sortedList.addAll(Arrays.asList(new String[] { "a", "b", "c", "d" }));

    int index = Collections.binarySearch(sortedList, "c");
    System.out.println(index);/*ww  w.j a v  a  2 s.  c o m*/

    index = Collections.binarySearch(sortedList, "e");
    System.out.println(index);
}

From source file:Main.java

public static void main(String args[]) {
    // create link list object 
    List<Integer> list = new LinkedList<Integer>();

    // populate the list  
    list.add(-8);/*from   w  w w  . j a v a2s. c  om*/
    list.add(4);
    list.add(-5);
    list.add(1);

    System.out.println("Min value is: " + Collections.min(list));
}

From source file:Main.java

public static void main(String args[]) {
    // create link list object 
    List<Integer> list = new LinkedList<Integer>();

    // populate the list  
    list.add(-1);/* ww  w  .  j a  v  a 2  s . c  o  m*/
    list.add(4);
    list.add(-5);
    list.add(1);

    System.out.println("Max value is: " + Collections.max(list));
}

From source file:Main.java

public static void main(String args[]) {
    // create linked list object        
    LinkedList<Integer> list = new LinkedList<Integer>();

    // populate the list 
    list.add(-2);/* w  w  w  .j  a v a 2  s  . c om*/
    list.add(2);
    list.add(-12);
    list.add(8);

    // sort the list
    Collections.sort(list, Collections.reverseOrder());

    System.out.println("List sorted in natural order: ");
    System.out.println(list);

}

From source file:Main.java

public static void main(String args[]) {
    // create link list object 
    List<Integer> list = new LinkedList<Integer>();

    // populate the list  
    list.add(-8);/*from w  w  w .  j a  v a 2s.c  o m*/
    list.add(4);
    list.add(-5);
    list.add(2);

    // comparing using natural ordering
    System.out.println("Min val: " + Collections.min(list));
    System.out.println("Min val: " + Collections.min(list, Collections.reverseOrder()));
}

From source file:Main.java

public static void main(String args[]) {
    // create link list object 
    List<Integer> list = new LinkedList<Integer>();

    // populate the list  
    list.add(-8);//from w w w.  j  av  a  2  s.co m
    list.add(4);
    list.add(-5);
    list.add(2);

    // comparing using natural ordering
    System.out.println("Max val: " + Collections.max(list));
    System.out.println("Max val: " + Collections.max(list, Collections.reverseOrder()));
}