- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
MS Excel
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
Physics
Chemistry
Biology
Mathematics
English
Economics
Psychology
Social Studies
Fashion Studies
Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
Java Program to double the size of an array
To double the size of an array, let us first create an array −
int arr[] = {5, 10, 15, 20, 25, 30, 35, 40, 45, 50};
Now, get the length of the above array −
int len = arr.length;
Double the size of the above array −
intnewArray[] = new int[len*2];
Now, newArray[] will be having twice the length of the array arr[].
Example
public class Demo { public static void main (String args[]) { int arr[] = {5, 10, 15, 20, 25, 30, 35, 40, 45, 50}; System.out.println("Length of initial array = " + arr.length); int len = arr.length; int newArray[] = new int[len*2]; System.arraycopy(arr, 0, newArray, 0, len); System.out.println("Length of new array = "+newArray.length); } }
Output
Length of initial array = 10 Length of new array = 20
- Related Articles
- Java Program to extend the size of an Integer array
- Java program to reverse an array in groups of given size
- How to extend the size of an array in Java
- Java Program to implement Binary Search on double array
- Python program to reverse an array in groups of given size?
- How to define an array size in java without hardcoding?
- Java Program to calculate the time of sorting an array
- Java Program to convert Double into String using toString() method of Double class
- Java Program to convert String to Double
- Java Program to Get the Size of the Collection
- Java program to reverse an array
- Java program to find the sum of elements of an array
- Java Program to copy an array from the specified source array
- C++ Program to find size of int, float, double and char in Your System
- MongoDB query to count the size of an array distinctly?

Advertisements