Login | Register   
LinkedIn
Google+
Twitter
RSS Feed
Download our iPhone app
TODAY'S HEADLINES  |   ARTICLE ARCHIVE  |   FORUMS  |   TIP BANK
Browse DevX
Sign up for e-mail newsletters from DevX


Tip of the Day
Language: Java
Expertise: Intermediate
May 15, 2017

Increasing the Size of an Array

public class ArraySize
{
    public static void main(String args[])
    {
        changeArraySize();
    }
    
    private static void changeArraySize()
    {
        int[] intArray = new int[5];

        System.out.println("Before change: size(): " + intArray.length);
        
        // Increasing the size by 2 times
        //Signature of Arrays.copyOf (original array, new length)
        intArray = java.util.Arrays.copyOf(intArray, intArray.length * 2);    
        System.out.println("After change: size(): " + intArray.length);
    }
}
M S Sridhar
 
Comment and Contribute

 

 

 

 

 


(Maximum characters: 1200). You have 1200 characters left.

 

 

Sitemap
Thanks for your registration, follow us on our social networks to keep up-to-date