Jump to content

Recommended Posts

Posted

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 elements

from the file again.

I apriciate all help!


Posted

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.

Posted

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));

}

Posted

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());
}

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 account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...