File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Beginning Java and the fly likes One more shot at removing an element from an array Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Reply locked New topic
Author

One more shot at removing an element from an array

Mike Osterhout
Ranch Hand

Joined: Jun 29, 2009
Posts: 84
I posted a similar topic and I was able to get this far



The problem is if you remove element 1 from the array it will print like this
0 this is the element
2 this is another element

This tells me that the null array is still there or in other words I am not bringing all non null elements to the front.

If this is the worst of my problems on this program I am not too worried but I would like to know why this isent working if possible.
Andre Brito
Ranch Hand

Joined: Dec 13, 2007
Posts: 95

I didn't understand it clearly.
You want 2 arrays: one if N elements and other with N-1 elements. Is that right?

I am not bringing all non null elements to the front.

That's happening because your index is not "controlled". In other words, if you have 2 arrays:
A -> [0][1][2]
B -> [0][0][0]

and you choose to delete the element "1", you're doing like this:
A -> [0][1][2]
B -> [0][null][2]

while (I guess) you want to do this
A -> [0][1][2]
B -> [0][2][null]

. Am I right?

You must pay attention to the index (in other words, the "i"). You have to create another index to control the second array.


Just remember: your code is your "portfolio". So you should organize it better, so other programmers can understand it
Mike Osterhout
Ranch Hand

Joined: Jun 29, 2009
Posts: 84
That works, however I am not sure why the int i doesnt work for both indexes

Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 38851
    
  23
Mike Osterhout wrote:I posted a similar topic . . .
Don't. Read this FAQ, please. Closing thread as duplicate. Please continue discussion here.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: One more shot at removing an element from an array