Exforsys
+ Reply to Thread
Results 1 to 3 of 3

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 ...

  1. #1
    Rahulbatra is offline Senior Member Array
    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.


  2. #2
    cyrus is offline Senior Member Array
    Join Date
    Apr 2006
    Answers
    128
    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;


  3. #3
    Rahulbatra is offline Senior Member Array
    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



Latest Article

Network Security Risk Assessment and Measurement

Read More...