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 ...
|
|||||||
| Register | FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read |
|
|||
|
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; |
|
|||
|
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?
|
![]() |
| Thread Tools | |
|
|
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| comp.lang.c Answers (Abridged) to Frequently Asked Questions (FAQ) | Steve Summit | Tech FAQ | 0 | 06-15-2004 07:00 AM |
| comp.lang.c Answers (Abridged) to Frequently Asked Questions (FAQ) | Steve Summit | Tech FAQ | 0 | 06-01-2004 07:01 AM |
| comp.lang.c FAQ list Table of Contents | Steve Summit | Tech FAQ | 0 | 06-01-2004 07:00 AM |
| comp.lang.c Answers to Frequently Asked Questions (FAQ List) | Steve Summit | Tech FAQ | 0 | 06-01-2004 07:00 AM |
| comp.lang.c Answers (Abridged) to Frequently Asked Questions (FAQ) | Steve Summit | Tech FAQ | 0 | 05-15-2004 07:00 AM |