The Artima Developer Community
Sponsored Link

Legacy Java Answers Forum
December 2001



This page contains an archived post to the Java Answers Forum made prior to February 25, 2002. If you wish to participate in discussions, please visit the new Artima Forums.


Partially Filled Arrays

Posted by Matt Gerrans on February 18, 2002 at 8:34 PM

Well, it is not completely clear what you are doing, but if I understand you correctly, then I believe you could accomplish your purpose either by using an array of Object (as opposed to int, or whatever other type you mean by "number"), or by using a Map.

Using an array of Object (or Integer, etc.), if an element has null, then it wasn't filled, otherwise you can cast it to Integer, or Float, or whatever your number type is.

Using a Map, you would really be creating a sparse array, as you would only insert elements where there are elements specified. Subsequently, you could have a loop that prints out which elements are (and are not) defined.

> i just finished a program on arrays that you could fill in your own number arrays or have random number arrays made. the random arrays was totally complete. but i couldnt figure out one step for the fill arrays.

> I was supposed to set the array so that the user would fill in 20 numbers for the area and i was supposed to modify the print numbers so that if the user did not fill out the 20 numbers it would just print what numbers the user inputed but i dont know how to do that.
> right now if the user puts in less than 20 numbers it will print those numbers and print out all zeroes for the amount that is left.

> can anyone help print only a partially filled array??


Sponsored Links

Copyright © 1996-2009 Artima, Inc. All Rights Reserved. - Privacy Policy - Terms of Use - Advertise with Us