• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Ron McLeod
  • Tim Cooke
  • Liutauras Vilda
  • Jeanne Boyarsky
Sheriffs:
  • Paul Clapham
  • Rob Spoor
  • Junilu Lacar
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Piet Souris
  • Carey Brown
Bartenders:

Changing an arrays size

 
Greenhorn
Posts: 23
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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).]
 
Ranch Hand
Posts: 1067
2
IntelliJ IDE Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.)
 
Rancher
Posts: 13459
Android Eclipse IDE Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Ranch Hand
Posts: 88
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
reply
    Bookmark Topic Watch Topic
  • New Topic