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

Object Arrays 

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 ObjectArrays.newArray() API. It returns a new array of the given length with the specified component type.

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

import java.util.Arrays;

import com.google.common.collect.ObjectArrays;

public class ObjectArraysTest {

  /**
   @param args
   */
  public static void main(String[] args) {
    Integer [] intArray = ObjectArrays.newArray(Integer.class, 4);
    System.out.println(Arrays.toString(intArray"  length : " + intArray.length);
    
    String [] strArray = ObjectArrays.newArray(String.class, 4);
    System.out.println(Arrays.toString(strArray"  length : " + strArray.length);
    
    Long [] longOrg = new Long [] { 1L2L3L4L };
    Long [] longArray = ObjectArrays.newArray(longOrg, 2);
    System.out.println(Arrays.toString(longArray"  length : " + longArray.length);
  }

}
   

It gives the following output,
[null, null, null, null]  length : 4
[null, null, null, null]  length : 4
[null, null]  length : 2


                    Print

   



Books Recommendation

 
 
bl  br