Win a copy of The Java Performance Companion this week in the Performance forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Changing an arrays size

 
Ryan Perlman
Greenhorn
Posts: 23
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 986
Eclipse IDE Firefox Browser Tomcat Server
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You need a more flexable data structure, arrays are rather static. (Sorry I didn't actaully look at your code.)
 
David O'Meara
Rancher
Posts: 13459
Android Eclipse IDE Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
Dave.
 
Colin Kenworthy
Ranch Hand
Posts: 88
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic