File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Beginning Java and the fly likes Changing an arrays size Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Changing an arrays size " Watch "Changing an arrays size " New topic

Changing an arrays size

Ryan Perlman

Joined: Oct 31, 2001
Posts: 23
I am trying to change the arrays size if some condition is not met.
my user will input 20 numbers between 10 and 100 if one is a duplicate of the other don't add it to the array. here is the code I have. It won't add the duplicate number but it sets that array to zero instead I just want to eliminate that
The code

ANY help is appreciated Ryan

[This message has been edited by Ryan Perlman (edited November 15, 2001).]
William Barnes
Ranch Hand

Joined: Mar 16, 2001
Posts: 986

You need a more flexable data structure, arrays are rather static. (Sorry I didn't actaully look at your code.)

Please ignore post, I have no idea what I am talking about.
David O'Meara

Joined: Mar 06, 2001
Posts: 13459

You'd have to ask the question in the Performance forum as to whether it is a good thing, but previously I have used the System.arraycopy() method. I tend to use the Collections framework rather than arrays (except on the rare occasion) so it's been a while.
Colin Kenworthy
Ranch Hand

Joined: Aug 06, 2001
Posts: 88
Once you create an array it's size cannot be changed. You could (once your 20 numbers have been input) go through your array counting the non-zero ints and create a new array of that size, then go through again copying accross the non-zero ints.
OR you could get into Collections (in which case you would need to use the Integer class instead of int) and discover how simple it is to manipulate a set of objects like Integer.
I agree. Here's the link:
subject: Changing an arrays size
It's not a secret anymore!