tl  tr
  Home | Tutorials | Articles | Videos | Products | Tools | Search
Open Source | Tag Cloud | Follow Us | Bookmark | Contact   
 
 Tools and Libs > Google Guava > Collections > Immutable List

Immutable List 

Google Guava is a java library with lot of utilities and reusable components. This requires the library guava-10.0.jar to be in classpath. The following example shows using ImmutableList class. It returns an immutable list implementation which doesn't allow null elements.

File Name  :  
com/bethecoder/tutorials/guava/collection_tests/ImmutableListTest.java 
Author  :  Sudhakar KV
Email  :  kvenkatasudhakar@gmail.com
   
package com.bethecoder.tutorials.guava.collection_tests;

import java.util.Arrays;
import java.util.List;

import com.google.common.collect.ImmutableList;

public class ImmutableListTest {

  /**
   @param args
   */
  public static void main(String[] args) {
    ImmutableList<String> stringList = ImmutableList.of("ONE""TWO""THREE""FOUR");
    System.out.println(stringList);
    
    List<Integer> ints = Arrays.asList(1223334444);
    ImmutableList<Integer> intList = ImmutableList.copyOf(ints.iterator());
    System.out.println(intList);
  }

}
   

It gives the following output,
[ONE, TWO, THREE, FOUR]
[1, 2, 2, 3, 3, 3, 4, 4, 4, 4]


                    Print

   



Books Recommendation

 
 
bl  br