Lavdim Posted November 17, 2005 Share Posted November 17, 2005 How can I add elements to a arraylist(I have 5 attributes to add to the arraylist,thoose should be added as the user type them), then save them to a file and be able to read the elementsfrom the file again. I apriciate all help! Link to comment Share on other sites More sharing options...
Dutchdre Posted November 17, 2005 Share Posted November 17, 2005 We cant reply your question if we dont know which programming language you use! Link to comment Share on other sites More sharing options...
Lavdim Posted November 17, 2005 Author Share Posted November 17, 2005 Oh sorry...I have forgotten to say wich language.. it`s Java. Link to comment Share on other sites More sharing options...
Dutchdre Posted November 18, 2005 Share Posted November 18, 2005 It depends on what you store in the ArrayList.I think if it are Strings you could write them to a file, each element a new line something like that. Link to comment Share on other sites More sharing options...
Lavdim Posted November 20, 2005 Author Share Posted November 20, 2005 I have managed to add elements to the ArrayList that I have created. But now I have problems to get the elements that I have stored. For the moment they are not stored in any file, only in the buffer when I execute the program. I have 5 attributes that I store, 4 are String, 1 is int. This is how I have tried to get them:(Arrangements is the arraylist) for (int i = 0; i < Arrangements.size(); i++) { System.out.println(Arrangements.get(i)); } Link to comment Share on other sites More sharing options...
Dutchdre Posted November 21, 2005 Share Posted November 21, 2005 You can better use an Iterator, this class can also handle other collections than ArrayLists.Iterator it = Arrangements.iterator();while(it.hasNext()) { System.out.println(it.next());} Link to comment Share on other sites More sharing options...
RayOK Posted November 21, 2005 Share Posted November 21, 2005 (edited) nm.. looked right over the list part Edited November 21, 2005 by RayOK Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now