File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Beginning Java and the fly likes ArrayList Use Question Big Moose Saloon
  Search | Java FAQ | Recent Topics
Register / Login


Win a copy of The Mikado Method this week in the Agile and other Processes forum!
JavaRanch » Java Forums » Java » Beginning Java
Reply Bookmark "ArrayList Use Question" Watch "ArrayList Use Question" New topic
Author

ArrayList Use Question

G. Graz
Ranch Hand

Joined: Oct 23, 2006
Posts: 30
I am trying to populate an ArrayList using user input. Each input I thought should register as it's own index in the ArrayList ? Problem I am having is my ArrayList is only holding the current value that was entered, should I have some type of loop that will add the elements to the array ? and/or am I using the ArrayList in the wrong way ? Thank you !

Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 56217
    
  13

You're creating a new list each time.


[Smart Questions] [JSP FAQ] [Books by Bear] [Bear's FrontMan] [About Bear]
Kumaresh Vidhyasagar
Ranch Hand

Joined: Dec 05, 2008
Posts: 30
Just create the instance of the arraylist before the while loop. It will work
G. Graz
Ranch Hand

Joined: Oct 23, 2006
Posts: 30
Bingo !!! So simple and I did not even see it ! Thank you again for the extra set of eyes !
 
I agree. Here's the link: http://ej-technologies/jprofiler - if it wasn't for jprofiler, we would need to run our stuff on 16 servers instead of 3.
 
subject: ArrayList Use Question
 
Similar Threads
Quick question about new object
TestScores
validations problems(decimal value check?)
TestScores
try...catch blocks giving <identifier> expected error