
- Forum
- Programming Talk
- Java
- Array Handling
Array Handling
This is a discussion on Array Handling within the Java forums, part of the Programming Talk category; I have an array defined in Java as below: Test[] a = new Test[100]; The array is full. I want ...
-
05-02-2007, 04:34 PM #1
- Join Date
- Apr 2006
- Answers
- 124
Array Handling
I have an array defined in Java as below:
Test[] a = new Test[100];
The array is full. I want to grow this array. But I want to achieve the growing of array such that array grow is done for any type, not just arrays of objects.
-
Test[] a = new Test[100];
You can grow the array Test as below
int arraynewl = a.length * 15 / 12 + 12;
The above statement computes the length of the new array to be defined that is length of the new grow array.
Now assign the new length to the array and define it newly as
Test[] arrayn = new Test[arraynewl];
System.arraycopy(a, 0, arrayn, 0, a.length);
a = arrayn;
-
05-08-2007, 05:43 PM #3
- Join Date
- Apr 2006
- Answers
- 124
Thanks it was a very good suggestion. I tried this and also got the result. But if we make the above generic that is the growing of array such that array growth is done for any type, not just arrays of objects. Can you provide idea to achieve this?
-
Sponsored Ads

Reply With Quote





