473,322 Members | 1,540 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,322 software developers and data experts.

compare two ArrayLists

281 100+
Friends, I need some inputs about my java program. My program is supposed to store 3 information into an ArrayList so-called arrayOne at each runtime:
1. Unique ID
2. Boolean Value
3. data.

Let's assume I give first input a = 5, compile & run: Result - arrayOne.
Second Input a = 24, compile & run: Result - arrayOne.
Aim: To compare these two result arrays after runtime.

How to extract the results & compare these 2 result arrays after runtime that can automatically check the data & boolean value?

please advise and I'll post my program then...
Apr 2 '07 #1
28 8867
r035198x
13,262 8TB
Friends, I need some inputs about my java program. My program is supposed to store 3 information into an ArrayList so-called arrayOne at each runtime:
1. Unique ID
2. Boolean Value
3. data.

Let's assume I give first input a = 5, compile & run: Result - arrayOne.
Second Input a = 24, compile & run: Result - arrayOne.
Aim: To compare these two result arrays after runtime.

How to extract the results & compare these 2 result arrays after runtime that can automatically check the data & boolean value?

please advise and I'll post my program then...
If you want the results after the program has exited then you need to write the results to a file or database.
Apr 2 '07 #2
shana07
281 100+
If you want the results after the program has exited then you need to write the results to a file or database.
Please give me some pointer on how to write result into a file ..
and compare them ...at least any web page for my reading..thanks a lot
Apr 2 '07 #3
r035198x
13,262 8TB
Please give me some pointer on how to write result into a file ..
and compare them ...at least any web page for my reading..thanks a lot
Last week's tip of the week talked about writing to a textfile. In this case however you should write the Arraylist to the file as an object using serialization.
Apr 2 '07 #4
shana07
281 100+
Last week's tip of the week talked about writing to a textfile. In this case however you should write the Arraylist to the file as an object using serialization.
Yes, I've gone through it and I do remember last time you taught me how to transfer/export result into a file using FileOutputStream.
Now I managed to get it done. Next, how am I supposed to do to compare the second result(new input) after second program has exited?
hope you can guide me please...

o ya I print result in a txt file...or maybe I need to print in other format in order for me to compare them automatically? idea please...thank you
Apr 3 '07 #5
r035198x
13,262 8TB
Yes, I've gone through it and I do remember last time you taught me how to transfer/export result into a file using FileOutputStream.
Now I managed to get it done. Next, how am I supposed to do to compare the second result(new input) after second program has exited?
hope you can guide me please...

o ya I print result in a txt file...or maybe I need to print in other format in order for me to compare them automatically? idea please...thank you
If you wrote the ArrayList to the file as an object like you should have then you can retrieve it using the readObject method of ObjectInputStream and type cast it to the ArrayList.
Apr 3 '07 #6
shana07
281 100+
If you wrote the ArrayList to the file as an object like you should have then you can retrieve it using the readObject method of ObjectInputStream and type cast it to the ArrayList.
From my understanding, what you mean is while the second program is still running retrieve the first output from text file using the readObject() from ObjectInputStream class and automatically compare them?

please correct me if I'm wrong...
Apr 3 '07 #7
r035198x
13,262 8TB
From my understanding, what you mean is while the second program is still running retrieve the first output from text file using the readObject() from ObjectInputStream class and automatically compare them?

please correct me if I'm wrong...
I'm not too sure about the "automatically" part but that's the jists of it.
Apr 3 '07 #8
shana07
281 100+
I'm not too sure about the "automatically" part but that's the jists of it.
Alright, thanks for your valuable idea. Please guide me how to retrieve the first executed program result...Do I need to call readObject() from the ArrayList place or create another new method - ObjectInputStream or from here:
Expand|Select|Wrap|Line Numbers
  1. public static void print(String s) 
  2.   {      
  3.       try
  4.         {
  5.             FileOutputStream fout;    
  6.         fout = new FileOutputStream ("output.txt",true);    
  7.             new PrintStream(fout).println (s);   
  8.         fout.close();
  9.         }
  10.  
  11.       catch (IOException ex) 
  12.       {
  13.           System.out.println("There was a problem creating/writing to the temp file");
  14.           ex.printStackTrace();
  15.       }   
  16.   }   
Apr 3 '07 #9
r035198x
13,262 8TB
Alright, thanks for your valuable idea. Please guide me how to retrieve the first executed program result...Do I need to call readObject() from the ArrayList place or create another new method - ObjectInputStream or from here:
Expand|Select|Wrap|Line Numbers
  1. public static void print(String s) 
  2. try
  3. {
  4. FileOutputStream fout;    
  5.      fout = new FileOutputStream ("output.txt",true); 
  6. new PrintStream(fout).println (s); 
  7.      fout.close();
  8. }
  9.  
  10. catch (IOException ex) 
  11. {
  12.      System.out.println("There was a problem creating/writing to the temp file");
  13.      ex.printStackTrace();
What is that code suppposed to be doing?

You should write the ArrayList to the file using an ObjectOutputstream first in the first program, then you can retrieve it from the file in the second program
Apr 3 '07 #10
shana07
281 100+
What is that code suppposed to be doing?

You should write the ArrayList to the file using an ObjectOutputstream first in the first program, then you can retrieve it from the file in the second program
In general the final result of my program is to collect/store 3 types of data:
1. Unique ID
2. Boolean Value
3. data.
I use ArrayList to store those information
Expand|Select|Wrap|Line Numbers
  1. List listOne = new ArrayList();
  2. ....
  3. //looping for collect required data
  4. ....
  5. listOne.add(new Entry(ID, data, value));  
  6.                     print("ID: " +uniqueID);
  7.                     print("Data: " +data);
  8.                     print("value: " +value);
  9.  
Now you mean I have to change the ArrayList to the file using an ObjectOutputstream? But how..please gimme some pointer...
Apr 3 '07 #11
r035198x
13,262 8TB
In general the final result of my program is to collect/store 3 types of data:
1. Unique ID
2. Boolean Value
3. data.
I use ArrayList to store those information
Expand|Select|Wrap|Line Numbers
  1. List listOne = new ArrayList();
  2. ....
  3. //looping for collect required data
  4. ....
  5. listOne.add(new Entry(ID, data, value)); 
  6. print("ID: " +uniqueID);
  7. print("Data: " +data);
  8. print("value: " +value);
  9.  
Now you mean I have to change the ArrayList to the file using an ObjectOutputstream? But how..please gimme some pointer...
You write the whole arraylist as one object to a file and then retrieve it later. You write it to a file using ObjectOutputStream. Look at the docs for this class and see how can use it to store the whole arraylist into a file.
Apr 3 '07 #12
shana07
281 100+
You write the whole arraylist as one object to a file and then retrieve it later. You write it to a file using ObjectOutputStream. Look at the docs for this class and see how can use it to store the whole arraylist into a file.
Firstly, I've tried to write ArrayList as one object to a file, is that something like this? please check as I compile everything okay..but problem during runtime.
Expand|Select|Wrap|Line Numbers
  1. try
  2.         {
  3.             //  Create a stream for writing.
  4.             FileOutputStream fout  = new FileOutputStream ("output.txt",true);  
  5.             //  Next, create an object that can write to that file.
  6.             ObjectOutputStream oOutStream = new ObjectOutputStream( fout );
  7.  
  8.             //  Save each object.
  9.             oOutStream.writeObject(listOne);            
  10.  
  11.             oOutStream.flush();            
  12.             new PrintStream(fout).println (s);   
  13.             fout.close();         
  14.  
  15.         }
Apr 3 '07 #13
r035198x
13,262 8TB
Firstly, I've tried to write ArrayList as one object to a file, is that something like this? please check as I compile everything okay..but problem during runtime.
Expand|Select|Wrap|Line Numbers
  1. try
  2. {
  3. // Create a stream for writing.
  4. FileOutputStream fout = new FileOutputStream ("output.txt",true); 
  5. // Next, create an object that can write to that file.
  6. ObjectOutputStream oOutStream = new ObjectOutputStream( fout );
  7.  
  8. // Save each object.
  9. oOutStream.writeObject(listOne); 
  10.  
  11. oOutStream.flush(); 
  12. new PrintStream(fout).println (s); 
  13. fout.close(); 
  14.  
  15. }
Should be fine. I'm not sure what the line

Expand|Select|Wrap|Line Numbers
  1. new PrintStream(fout).println (s);   
is doing there though
Apr 3 '07 #14
shana07
281 100+
Should be fine. I'm not sure what the line

Expand|Select|Wrap|Line Numbers
  1. new PrintStream(fout).println (s);   
is doing there though
Still the same if I comment the line ..it's okay. i'll figure it out...
How about to retrieve back the data...? Let say after I finish this phase which is in the first program run - write result into a file namely A.
Second time I run program with different input produce new result, I do comparison directly in here by retrieve file A? Do I have to write to a new file namely B first or how, any idea...? thank you
Apr 3 '07 #15
itsraghz
127 100+
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....
Apr 3 '07 #16
shana07
281 100+
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....
Thank you friend. Your understanding about my aim is absolutely RIGHT.
After reading your notes I now know what is SERIALIZATION for (at least).
I would say that I need to proper digest your advice on how to implement it in my program...

Just one thing I don't get here is counter variable. If I am not mistaken, can I say that counter variable here is same as ArrayList size (in my case is oneList.size())?

Or I do have to create/generate a new variable as counter?Here I have class Entry (id, boolean,data).....

Thanks again....I shall try it first and see how it goes..
Apr 4 '07 #17
itsraghz
127 100+
Hi,

You are correct. The counter i meant to say was what you generate to keep track of the files.. So inorder to create the new value which is incremental of the previous value, you need the previous value. Thats why i told you should store the counter value also in a separate file.

Say, for the first time, you store the arraylist contents through Serialization in the file named "ArrayListContents-1.txt". The next iteration should store it in "ArrayListContents-2.txt". Right? For generating the 2, you need the previous value 1. Where would you take it? You should have stored it somewhere else and retrieve it now for incrementing it to be used this time.

Hope this clears..
Good luck.
Apr 4 '07 #18
shana07
281 100+
Hi,

You are correct. The counter i meant to say was what you generate to keep track of the files.. So inorder to create the new value which is incremental of the previous value, you need the previous value. Thats why i told you should store the counter value also in a separate file.

Say, for the first time, you store the arraylist contents through Serialization in the file named "ArrayListContents-1.txt". The next iteration should store it in "ArrayListContents-2.txt". Right? For generating the 2, you need the previous value 1. Where would you take it? You should have stored it somewhere else and retrieve it now for incrementing it to be used this time.

Hope this clears..
Good luck.
Phew! I feel dizzy doing this assignment, really :)

Now, I experience what you meant..It's complicated in second execution.
First part is done fairly easy (after you guys helped me), now I have problem on how to retrieve the ArrayListContents-2.txt.

At first I tried to make a loop from the current Entry size and retrieve the first output but having CONFLICT with the first Entry size that also has same variable name. oh god sorry if I make you confuse....I don't how to explain...If possible please take a look at my codes below:
Expand|Select|Wrap|Line Numbers
  1. listOne.add(new Entry(uniqueID, data, booleanValue));  
  2. try
  3.         {
  4.             FileOutputStream fout  = new FileOutputStream (FILENAME, true); 
  5.             ObjectOutputStream oos = new ObjectOutputStream( fout );            
  6.             oos.writeObject(uniqueID); 
  7.             oos.writeObject(data);
  8.             oos.writeObject(booleanValue);
  9.  
  10.             oos.flush(); 
  11.             fout.close();          
  12.  
  13.             FileInputStream fis = new FileInputStream(FILENAME);
  14.             ObjectInputStream ois = new ObjectInputStream(fis); 
  15.             Object obj = ois.readObject();
  16.  
  17.             List<Entry> listFromFile = (ArrayList) obj;
  18.         for (Entry listOne: listFromFile) 
  19.             {
  20.     try
  21.                 {
  22.                     FileInputStream fis1 = new FileInputStream("output1.txt");  //DO I HAVE TO CREATE NEW FIS FOR READING THE FIRST OUTPUT FILE?
  23.                     ObjectInputStream ois1 = new ObjectInputStream(fis1); 
  24.                     Object obj1 = ois1.readObject();
  25.  
  26.                    for (int i = 0; i <listOne.size(); i++)  //HERE IS THE CONFLICT!! -  SAME ARRAYLIST NAME CREATED
  27.                    {  
  28.                      Entry myEnt = (Entry)listOne.get(i);
  29.  
  30.                      if(myEnt.equalsId((Entry)listOne.get(i)))
  31.                      {
  32.                         if(myEnt.equalsData((Entry)listOne.get(i)))
  33.                         {
  34.                          if(myEnt.equals((Entry)listOne.get(i))) 
  35.                          { 
  36.                              System.out.println ("1");
  37.  
  38.                          }
  39.                         else 
  40.                         {
  41.                           System.out.println ("2");                  
  42.                         } 
  43.                      }
  44.                      else
  45.                         {
  46.                           System.out.println ("3");
  47.  
  48.                          } 
  49.                      }
  50.                    }    
  51.                 }
  52.  
  53.            catch (FileNotFoundException e) 
  54.           {
  55.                e.printStackTrace(); 
  56.           }
  57.            catch (IOException e) 
  58.            {
  59.               System.out.println("There was a problem creating/writing to the temp file");
  60.               e.printStackTrace();
  61.            } 
  62.            catch (ClassNotFoundException e) 
  63.            {
  64.                 e.printStackTrace();
  65.            } 
  66.          }
  67.  
  68.           }
  69.            catch (FileNotFoundException e) 
  70.           {
  71.                e.printStackTrace(); 
  72.           }
  73.            catch (IOException e) 
  74.            {
  75.               System.out.println("There was a problem creating/writing to the temp file");
  76.               e.printStackTrace();
  77.            } 
  78.            catch (ClassNotFoundException e) 
  79.            {
  80.                 e.printStackTrace();
  81.            } 
  82.  
  83.   }   
Apr 4 '07 #19
r035198x
13,262 8TB
Phew! I feel dizzy doing this assignment, really :)

Now, I experience what you meant..It's complicated in second execution.
First part is done fairly easy (after you guys helped me), now I have problem on how to retrieve the ArrayListContents-2.txt.

At first I tried to make a loop from the current Entry size and retrieve the first output but having CONFLICT with the first Entry size that also has same variable name. oh god sorry if I make you confuse....I don't how to explain...If possible please take a look at my codes below:
Expand|Select|Wrap|Line Numbers
  1. listOne.add(new Entry(uniqueID, data, booleanValue)); 
  2. try
  3. {
  4. FileOutputStream fout = new FileOutputStream (FILENAME, true); 
  5. ObjectOutputStream oos = new ObjectOutputStream( fout ); 
  6. oos.writeObject(uniqueID); 
  7. oos.writeObject(data);
  8. oos.writeObject(booleanValue);
  9.  
  10. oos.flush(); 
  11. fout.close(); 
  12.  
  13. FileInputStream fis = new FileInputStream(FILENAME);
  14. ObjectInputStream ois = new ObjectInputStream(fis); 
  15. Object obj = ois.readObject();
  16.  
  17. List<Entry> listFromFile = (ArrayList) obj;
  18.      for (Entry listOne: listFromFile) 
  19. {
  20.     try
  21. {
  22. FileInputStream fis1 = new FileInputStream("output1.txt"); //DO I HAVE TO CREATE NEW FIS FOR READING THE FIRST OUTPUT FILE?
  23. ObjectInputStream ois1 = new ObjectInputStream(fis1); 
  24. Object obj1 = ois1.readObject();
  25.  
  26. for (int i = 0; i <listOne.size(); i++) //HERE IS THE CONFLICT!! - SAME ARRAYLIST NAME CREATED
  27. Entry myEnt = (Entry)listOne.get(i);
  28.  
  29. if(myEnt.equalsId((Entry)listOne.get(i)))
  30. {
  31. if(myEnt.equalsData((Entry)listOne.get(i)))
  32. {
  33. if(myEnt.equals((Entry)listOne.get(i))) 
  34. System.out.println ("1");
  35.  
  36. }
  37. else 
  38. {
  39. System.out.println ("2"); 
  40. }
  41. else
  42. {
  43. System.out.println ("3");
  44.  
  45. }
  46. }
  47.  
  48. catch (FileNotFoundException e) 
  49. {
  50. e.printStackTrace(); 
  51. }
  52. catch (IOException e) 
  53. {
  54. System.out.println("There was a problem creating/writing to the temp file");
  55. e.printStackTrace();
  56. catch (ClassNotFoundException e) 
  57. {
  58. e.printStackTrace();
  59. }
  60.  
  61. }
  62. catch (FileNotFoundException e) 
  63. {
  64. e.printStackTrace(); 
  65. }
  66. catch (IOException e) 
  67. {
  68. System.out.println("There was a problem creating/writing to the temp file");
  69. e.printStackTrace();
  70. catch (ClassNotFoundException e) 
  71. {
  72. e.printStackTrace();
  73.  

You know you can just use one text file and one ArrayList of ArrayLists.

You always use that ArrayList to add new ArrayLists and so to the file you are working with only one ArrayList and it becomes easier to store and get.
Apr 4 '07 #20
itsraghz
127 100+
Yes thats right.. you could use a single file and a collection of ArrayLists in case you need to go for more and repeated runs.
Apr 4 '07 #21
shana07
281 100+
Yes thats right.. you could use a single file and a collection of ArrayLists in case you need to go for more and repeated runs.
But friends, how to do that..
Since the first execution will produce one ArrayList of Entry (MANY entries) with 3 attributes (for each entry) in a text file, then for the second execution, if I just use the same text file don't you think that it will replace the first output?

But then you're definitely right to just use a single file and collection of arraylists because I need to go for many loops in order to compare the attributes...but how?
Please guide me...........thanks a lot
Apr 5 '07 #22
r035198x
13,262 8TB
But friends, how to do that..
Since the first execution will produce one ArrayList of Entry (MANY entries) with 3 attributes (for each entry) in a text file, then for the second execution, if I just use the same text file don't you think that it will replace the first output?

But then you're definitely right to just use a single file and collection of arraylists because I need to go for many loops in order to compare the attributes...but how?
Please guide me...........thanks a lot
Before you write again to the ArrayList you first retrieve the one previously written to the file. then you add the new ArrayList to that ArrayList and write back the ArrayList of ArrayLists.
Apr 5 '07 #23
shana07
281 100+
Before you write again to the ArrayList you first retrieve the one previously written to the file. then you add the new ArrayList to that ArrayList and write back the ArrayList of ArrayLists.
I'm still working on it..by the way, friend of mine once said that I maybe need to change to FileReader/FileWriter in order to for me to save each attribute in a single line....and read the file line by line...
grr...clueless..
Apr 5 '07 #24
r035198x
13,262 8TB
I'm still working on it..by the way, friend of mine once said that I maybe need to change to FileReader/FileWriter in order to for me to save each attribute in a single line....and read the file line by line...
grr...clueless..
No. don't write line by line. You'd have to break up the ArrayList into into it's contents first and regroup them again when you read them. Just write one arraylist object to the file using serialization and if you need to add another arraylist then just add it as an element of that arraylist.
Apr 5 '07 #25
shana07
281 100+
No. don't write line by line. You'd have to break up the ArrayList into into it's contents first and regroup them again when you read them. Just write one arraylist object to the file using serialization and if you need to add another arraylist then just add it as an element of that arraylist.
Ok. The first execution output file written in per entry as one ArrayList variable - listOne.
Then for second time I don't know how to read them..what's the code to readObject:
this is my codes but I think it's wrong...
Expand|Select|Wrap|Line Numbers
  1.  List<Entry> listOne = new ArrayList<Entry>();
  2. ....
  3. try
  4.         {
  5.              /* RETRIEVE THE ONE PREVIOUSLY WRITTEN TO THE FILE */
  6.             FileInputStream fis = new FileInputStream(FILENAME);
  7.             ObjectInputStream ois = new ObjectInputStream(fis); 
  8.  
  9.             Object position = (listOne)ois.readObject(); //HERE- HOW TO RETRIEVE THEM AS THERE ARE 3 ATTRIBUTES THAT I HAVE TO COMPARE
  10.             Object number =  (listOne)ois.readObject();
  11.             value = ....
  12.  
Apr 5 '07 #26
r035198x
13,262 8TB
Ok. The first execution output file written in per entry as one ArrayList variable - listOne.
Then for second time I don't know how to read them..what's the code to readObject:
this is my codes but I think it's wrong...
Expand|Select|Wrap|Line Numbers
  1. List<Entry> listOne = new ArrayList<Entry>();
  2. ....
  3. try
  4. {
  5. /* RETRIEVE THE ONE PREVIOUSLY WRITTEN TO THE FILE */
  6. FileInputStream fis = new FileInputStream(FILENAME);
  7. ObjectInputStream ois = new ObjectInputStream(fis); 
  8.  
  9. Object position = (listOne)ois.readObject(); //HERE- HOW TO RETRIEVE THEM AS THERE ARE 3 ATTRIBUTES THAT I HAVE TO COMPARE
  10. Object number = (listOne)ois.readObject();
  11. value = ....
  12.  

Where is the ArrayList of ArrayLists?

You are supposed to have something like

Expand|Select|Wrap|Line Numbers
  1.  ArrayList lists = new ArrayList(); 
  2.  
  3. ArrayList listOne = new ArrayList();
  4. //add stuff to listOne
  5. lists.add(listOne);
  6.  
  7.  
then write lists to the file and save it there.
In program 2 get lists (using readObject) from the file.
get listOne using
listOne = lists.get(0);
If you want to save another arraylist in program 2 then simply to
lists.add(listTwo);
And you now have two arraylists inside lists. You can then overwrite the previous lists with this new one e.t.c
Apr 5 '07 #27
shana07
281 100+
Where is the ArrayList of ArrayLists?

You are supposed to have something like

Expand|Select|Wrap|Line Numbers
  1.  ArrayList lists = new ArrayList(); 
  2.  
  3. ArrayList listOne = new ArrayList();
  4. //add stuff to listOne
  5. lists.add(listOne);
  6.  
  7.  
then write lists to the file and save it there.
In program 2 get lists (using readObject) from the file.
get listOne using
listOne = lists.get(0);
If you want to save another arraylist in program 2 then simply to
lists.add(listTwo);
And you now have two arraylists inside lists. You can then overwrite the previous lists with this new one e.t.c
I don't have ArrayList of ArrayLists (I think).. I only have
Expand|Select|Wrap|Line Numbers
  1. List<Entry>listOne = new ArrayList<Entry>(); 
Because of I have class Entry which I think is the same as what you mentioned ArrayList in here. I don't know. maybe you can have a look at the Entry Class as below:
Expand|Select|Wrap|Line Numbers
  1. class Entry 
  2. {
  3.    public Object IdNumber;
  4.    public Object data;
  5.    public boolean value;
  6.  
  7.    public Entry(Object IdNumber, Object data, boolean value)
  8.  {
  9.      this.IdNumber = IdNumber;
  10.      this.data = data;
  11.      this.value    = value;    
  12.   }  
  13.  
  14.      public boolean equals(Entry e) 
  15.    { 
  16.      return value != e.value;
  17.    }  
  18. }
So I just add stuff to listOne such this:
Expand|Select|Wrap|Line Numbers
  1. listOne.add(new Entry( IdNumber, data, value));
Then, that's why I write these 3 attributes in a text file like this:
Expand|Select|Wrap|Line Numbers
  1. oos.writeObject ( IdNumber); //CAN I WRITE EACH OBJECT ONE BY ONE TO TEXT FILE? THEN LATER I GONNA HAVE PROBLEM HOW/WHAT IS THE CODE TO RETRIEVE THEM. 
  2. oos.writeObject(data); //save each object
  3. oos.writeObject(value);
  4. oos.flush(); 
  5. fout.close(); 
So still do I need to create an ArrayList to replace the Entry? I understand what you meant here, because later I have to retrieve them one ArrayList per ArrayList. In my case, can it be as Entry per entry?
Please teach me how/what is the code...thanks a lot.
Apr 6 '07 #28
shana07
281 100+
does anyone care to share some ideas with me about ArrayLists? Really appreciate any help. Thank You.
Apr 11 '07 #29

Sign in to post your reply or Sign up for a free account.

Similar topics

5
by: Jim H | last post by:
I will have many 3 byte Byte arrays. Is there a way to compare the values without iterating through and comparing each element in the code? Example: byte lTest1 = new byte {0x1, 0x2, 0x3};...
4
by: Gaby | last post by:
Hi all, What is the best way to compare 2 (large) ArrayLists filled with an object. Can you please help me? Gaby
1
by: godsella | last post by:
First i have two stored procedures, i have passed the values of each one into two different arraylists of dates. how can i compare the two arraylists of dates? Thanks in advance
5
by: drdave | last post by:
I would like to have ten arraylists created within a loop.. is there a conversion or something I can do to acheive this.. pseudo: Dim counter As Integer = 0 Dim ArrName As ArrayList ...
4
by: Andy in S. Jersey | last post by:
I would like to create an unknown number of Arraylists, meaning, I don't know how many I should create until runtime. I will be reading a table, and 0,1,2, or more fields have to be put into...
2
by: Andy in S. Jersey | last post by:
I would like to create an unknown number of ArrayLists, that is I don't know that until runtime. Of course I can do this if I knew I needed two: ArrayList IntervalArray1 = new ArrayList();...
1
by: Newbie19 | last post by:
I'm just learning java arrays/arraylists and was wondering what are the best books for learning java arrays/arraylists? I know practice is the best way to learn, but I have a hard time...
26
by: CodeTilYaDrop | last post by:
Does anyone know how to compare contents of two ArrayLists? I want to compare them to see if they match up. Do you have an example or could you point me in the right direction. I know I need to...
3
by: irobot | last post by:
Hi. I would like to ask how to compare three or more Arraylists? I need to dublicate ellements from Arraylists, in order to filter datagridview. I would like to choose from 1 to 5 Arraylists. I...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.