The Artima Developer Community
Sponsored Link

Legacy Java Answers Forum
April 2001

Advertisement

Advertisement

This page contains an archived post to the Java Answers Forum made prior to February 25, 2002. If you wish to participate in discussions, please visit the new Artima Forums.

Message:

Re: Removing an element from a one dimensional array

Posted by uday on May 15, 2001 at 1:13 AM

Hi dean,

True. If you do in that way, an empty element will be left over. So if you use an array of Integer objects you don't have any option left other than creating a new array, since array size is fixed, it can not grow/shrink dynamically.

Instead you can use vector to store the Integer objects. Vector can grow & shrink dynamically.

You can store Integer objects ( not int ) in the vector. If you are using int means, probably you'll have to create new array.

Hope it helps
thanks
-uday

> I am having trouble removing an element from an array. I can search and find the position in the array, but when I delete the position using:

> data[position] = null;

> There will be an empty position in the array. How do you get rid of this empty position?

> Do you have to create a new array with its size one less than the previous, or is there an easier way.

> P.S My array does not contain objects, it contains Integers.

> Thanks in advance

> Dean






Replies:

Sponsored Links



Google
  Web Artima.com   
Copyright © 1996-2009 Artima, Inc. All Rights Reserved. - Privacy Policy - Terms of Use - Advertise with Us