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 storing values into an array Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "storing values into an array" Watch "storing values into an array" New topic

storing values into an array

Mike Pirrone
Ranch Hand

Joined: Oct 30, 2001
Posts: 33
ok, we are all the way up to inheritance at this point in my class but I am still having problems with storing values into an array. are there any websites that could offer me some help on the subject? I can declare an array perfectly but what I am trying to figure out, is how to store values that a user enters into an array and then print out the entire array of values that the user entered. thank you so much
Dirk Schreckmann

Joined: Dec 10, 2001
Posts: 7023
Two cents on arrays...
First penny: array + loop = beauty and power
The beauty of using arrays is realized with the power of looping. We don't have to code repititiously for each component in the array - we use the repitions of a loop.
So, to fill an array with data and then display the components in the array, you could:
1. declare and intialize your array with some length
2. use a for loop to prompt the user for data and add that data to the array until the end of the array is reached
3. use another for loop to display the entire contents of the array
These for loops could look something like:

Second penny: If you were to do a search on this forum (the search page link is at the top right of this page), I'd bet you'd find lots of useful information on arrays (and many other topics).
Good Luck.
[ April 02, 2002: Message edited by: Dirk Schreckmann ]

[How To Ask Good Questions] [JavaRanch FAQ Wiki] [JavaRanch Radio]
Corey McGlone
Ranch Hand

Joined: Dec 20, 2001
Posts: 3271
If you ever get confused about an array, just draw a picture. You'll find that arrays are very easy once you can visualize them. Take a look at this example:

In this picture, I have the array indices drawn over the top of the array. Now, if I want to get the value 101 out of the array, I'd access intArray[1]. If I wanted to get 103, I'd access intArray[3].
Drawing pictures always makes things easier for me. Hopefully, this will help you, too.

SCJP Tipline, etc.
I agree. Here's the link:
subject: storing values into an array
jQuery in Action, 3rd edition