Advertisement
If you have a new account but are having problems posting or verifying your account, please email us on hello@boards.ie for help. Thanks :)
Hello all! Please ensure that you are posting a new thread or question in the appropriate forum. The Feedback forum is overwhelmed with questions that are having to be moved elsewhere. If you need help to verify your account contact hello@boards.ie

Shrinking an array in Java.

Options
  • 06-10-2005 12:10pm
    #1
    Registered Users Posts: 21,264 ✭✭✭✭


    I have something like this...
    String[] list = new String[100];
    
    now I have it filled with data but I want to cull it do that they get an array back of x

    eg.
    String[] newList = myClass.getList(x); 
    
    Do I have to create a new array and step through the other array copying? or is there a faster method?
    String[] returnList = new String[x];
    for (int i = 0; i < x; i++) { 
      returnList[i] = list[i];
    }
    
    return returnList;
    


Comments

Advertisement