File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Java in General and the fly likes Is there an array class which resequences itself? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Java in General
Bookmark "Is there an array class which resequences itself?" Watch "Is there an array class which resequences itself?" New topic
Author

Is there an array class which resequences itself?

Dan Kempten
Greenhorn

Joined: Dec 26, 2008
Posts: 25
Arrays are awful

After dealing with arrays like this : XyArray myXyArray = new XyArray[20];

and all that kind of stuff I've stepped up into : List<Xy> myXyArray = new ArrayList();

Still I find that when my List<Xy> array has three objects, with name attributes "One", "Two", "Three"
and I delete the object "Two", then the List<Xy> array *still* thinks that it's size is 3

Example : I do this :


and it thinks that when i = 0 the object is "One"
when i = 1 the object is "Three"
when i = 2 !!! hey !!! why is size() still 3 ???

Question : must I extend List / ArrayList to add the concept of reducing size after removing???
Or is there an Array class with this included already in existence???

Thanks for any tips.
Marco Ehrentreich
best scout
Bartender

Joined: Mar 07, 2007
Posts: 1280

What exactly is xyOne, xyTwo and xyThree?
Marco Ehrentreich
best scout
Bartender

Joined: Mar 07, 2007
Posts: 1280

Oh, I didn't notice this before... Is it a typo or do you remove xyTwo from the wrong list? You are adding elements to "myXyArray" but you are trying to remove an element from "xyArray". Maybe that explains the unexpected behavior?

Marco
Dan Kempten
Greenhorn

Joined: Dec 26, 2008
Posts: 25
Xy xyOne;
Xy xyTwo;
Xy xyThree;

This problem has been resolved but I am not sure how.
Marco Ehrentreich
best scout
Bartender

Joined: Mar 07, 2007
Posts: 1280

Probably you should post all the relevant parts of your code if you're expecting to get answers here. Nobody knows how the class Xy looks like.
Winston Gutkowski
Bartender

Joined: Mar 17, 2011
Posts: 7779
    
  21

Dan Kempten wrote:This problem has been resolved but I am not sure how.

Us neither, because you haven't provided us with what you ran.

1. It doesn't compile.
2. Marco already pointed you to your typo. If that is, in fact, what you ran, then nothing would have been removed from myXyArray.

The fact is: size() does update after a successful remove(), except (possibly) in multi-threaded situations; so plainly you were doing something else wrong.

Winston

Isn't it funny how there's always time and money enough to do it WRONG?
Articles by Winston can be found here
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Is there an array class which resequences itself?