Hi,
If my understanding on your requirement is right, you want to have a program which will read the inputs (say the different data - id, boolean,data) and store them into an ArrayList. For every run [assume, as of now your requirement is only 2 times], the program should compare the individual values of the present run with that of the previously entered values.
In order to get the previously entered values, we should store the data somewhere so that we can fetch it later. Since the control/scope is lost once the program execution finishes, we can't store the data with any variables. The only way is to store it to any permanent storage medium so that you can get it back. Thats why the SERIALIZATION comes in - the easy way of managing things.
You can think Serialization as equal to store it into the database but with the different arena. {thats not our scope now, i assume you are comfortable with serialization by now}.
Now, the main part is, for every time you run, you first get the values from the user and populate your arraylist object with these values. Then fetch the previous values and compare the individual attributes/values.
What you can do is,
(a) Keep a counter variable which you append it to the end of the file.
You retrieve this value and increment it for the next file to be stored.But you should store the counter variable also in another file !!
(b) You can append the current datetime value with the filename while storing it. No matter how many files are present, you just keep writing a new file everytime. While retrieving, you just instantiate different arraylist objects as that of number of files in the directory. Then you can compare the values.
Hope this helps....
If my understanding on your requirement is right, you want to have a program which will read the inputs (say the different data - id, boolean,data) and store them into an ArrayList. For every run [assume, as of now your requirement is only 2 times], the program should compare the individual values of the present run with that of the previously entered values.
In order to get the previously entered values, we should store the data somewhere so that we can fetch it later. Since the control/scope is lost once the program execution finishes, we can't store the data with any variables. The only way is to store it to any permanent storage medium so that you can get it back. Thats why the SERIALIZATION comes in - the easy way of managing things.
You can think Serialization as equal to store it into the database but with the different arena. {thats not our scope now, i assume you are comfortable with serialization by now}.
Now, the main part is, for every time you run, you first get the values from the user and populate your arraylist object with these values. Then fetch the previous values and compare the individual attributes/values.
What you can do is,
(a) Keep a counter variable which you append it to the end of the file.
You retrieve this value and increment it for the next file to be stored.But you should store the counter variable also in another file !!
(b) You can append the current datetime value with the filename while storing it. No matter how many files are present, you just keep writing a new file everytime. While retrieving, you just instantiate different arraylist objects as that of number of files in the directory. Then you can compare the values.
Hope this helps....
Comment