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

New ArrayList 

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 Lists.newArrayList() API. It returns a mutable ArrayList object containing the given elements.

File Name  :  
com/bethecoder/tutorials/guava/collection_tests/NewArrayListTest.java 
Author  :  Sudhakar KV
Email  :  [email protected]
   
package com.bethecoder.tutorials.guava.collection_tests;

import java.util.List;

import com.bethecoder.tutorials.guava.common.Student;
import com.google.common.collect.Lists;

public class NewArrayListTest {

  /**
   @param args
   */
  public static void main(String[] args) {
    List<String> stringList = Lists.newArrayList("ONE""TWO""THREE");
    System.out.println(stringList);
    
    List<Integer> intList = Lists.newArrayList(1234);
    System.out.println(intList);
    
    Student student = new Student("Sriram"2"Chess");
    Student student2 = new Student("Venkat"28"Cricket");
    List<Student> studList = Lists.newArrayList(student, student2);
    System.out.println(studList);
  }

}
   

It gives the following output,
[ONE, TWO, THREE]
[1, 2, 3, 4]
[com.bethecoder.tutorials.guava.common.Student@69b332, 
	com.bethecoder.tutorials.guava.common.Student@173a10f]



 
  


  
bl  br