473,405 Members | 2,379 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,405 software developers and data experts.

java.util.List

281 100+
Hi again, would like to consult about List problem.

//start code
Expand|Select|Wrap|Line Numbers
  1.  java.util.List ifs = new java.util.ArrayList();
  2.  
// we're in the 'getMonitor' method
Expand|Select|Wrap|Line Numbers
  1.    Instruction insn = jvm.getLastInstruction();     
  2.    ……… 
  3.    ………
  4.    if (insn instanceof IfInstruction) 
  5. {
  6.      IfInstruction iff = (IfInstruction) insn;
  7.      Object position = insn.getOffset();
  8.      boolean value = iff.getConditionValue();
  9.      ifs.add(new Entry(position, value));
  10.  
  11.     System.out.print(position);
  12.     System.out.println();
  13.     System.out.print(value);
  14.     System.out.println();
  15.  
  16.     Iterator iter = ifs.iterator();
  17.     while (iter.hasNext()) {
  18.                   System.out.println("string " + iter.next());
  19.                   }
  20.     System.out.print(ifs.size());
  21.     System.out.println();              
  22.    }
  23. // ... the rest of the method are here
  24.  
Expand|Select|Wrap|Line Numbers
  1. class Entry {
  2.    public Object position;
  3.    public boolean value;
  4.  
  5.    public Entry(Object position, boolean value) {
  6.      this.position = position;
  7.      this.value    = value;
  8.    }
  9. }
  10.  
Now what happen is I need to call those fields above in a method ‘report’
(in the same file – TestDriver.java). Here comes my question:
1. How am I supposed to call single value/position without call Entry as a whole?
E.g: I want to compare value of index 1 and index 0 - which I have read inputs from Array.
Expand|Select|Wrap|Line Numbers
  1. void report( )
  2. ………
  3. ………
  4. //ifs.get(1) != ifs.get(0) 
  5. //I don't need this because it is getting compare the
  6. //whole Entry.I need something like this: 
  7.  
  8. if (ifs.value(1) != ifs.value(0)) //For sure errors encountered! 
  9.    {
  10.         System.out.println (“A”);
  11.     }
  12.     else 
  13.     {
  14.         System.out.println (“B”);
  15.     }            
  16.  
Please advise me. thanks guys...
Feb 2 '07 #1
48 4540
r035198x
13,262 8TB
Hi again, would like to consult about List problem.

//start code
Expand|Select|Wrap|Line Numbers
  1.  java.util.List ifs = new java.util.ArrayList();
  2.  
// we're in the 'getMonitor' method
Expand|Select|Wrap|Line Numbers
  1. Instruction insn = jvm.getLastInstruction(); 
  2. ……… 
  3. ………
  4. if (insn instanceof IfInstruction) 
  5. {
  6. IfInstruction iff = (IfInstruction) insn;
  7. Object position = insn.getOffset();
  8. boolean value = iff.getConditionValue();
  9. ifs.add(new Entry(position, value));
  10.  
  11. System.out.print(position);
  12. System.out.println();
  13. System.out.print(value);
  14. System.out.println();
  15.  
  16. Iterator iter = ifs.iterator();
  17. while (iter.hasNext()) {
  18. System.out.println("string " + iter.next());
  19. }
  20. System.out.print(ifs.size());
  21. System.out.println(); 
  22. }
  23. // ... the rest of the method are here
  24.  
Expand|Select|Wrap|Line Numbers
  1. class Entry {
  2. public Object position;
  3. public boolean value;
  4.  
  5. public Entry(Object position, boolean value) {
  6. this.position = position;
  7. this.value = value;
  8. }
  9. }
  10.  
Now what happen is I need to call those fields above in a method ‘report’
(in the same file – TestDriver.java). Here comes my question:
1. How am I supposed to call single value/position without call Entry as a whole?
E.g: I want to compare value of index 1 and index 0 - which I have read inputs from Array.
Expand|Select|Wrap|Line Numbers
  1. void report( )
  2. ………
  3. ………
  4. //ifs.get(1) != ifs.get(0) 
  5. //I don't need this because it is getting compare the
  6. //whole Entry.I need something like this: 
  7.  
  8. if (ifs.value(1) != ifs.value(0)) //For sure errors encountered! 
  9. {
  10. System.out.println (“A”);
  11. }
  12. else 
  13. {
  14. System.out.println (“B”);
  15.  
Please advise me. thanks guys...
Do you have objects of type Entry in the ArrayList? Do you want to compare two Entry objects using the attribute position only?
Feb 2 '07 #2
shana07
281 100+
I’m not too sure to answer your Q. What I’ve understood is Yes I have objects of type Entry. First I ran those codes with int a[0] and try to record the attribute value at each IF* bytecode. So the output from this code giving – 4 Entry for first execution.
Expand|Select|Wrap|Line Numbers
  1. Iterator iter = ifs.iterator();
  2. while (iter.hasNext()) 
  3. {
  4.    System.out.println("string " + iter.next());  }
  5. System.out.print(ifs.size());
  6.  
Then I ran again the execution to execute second int a value from array and try to compare the current ifs.value of int a[1] with previous ifs.value of int a[0]. So in short - to compare two Entry of two objects int a[1] and int a[0] using attribute ‘value’ only.
Feb 2 '07 #3
shana07
281 100+
Then I ran again the execution to execute second int a value from array and try to compare the current ifs.value of int a[1] with previous ifs.value of int a[0]. So in short - to compare two Entry of two objects int a[1] and int a[0] using attribute ‘value’ only.
Sorry for confusing you guys..I think to compare two collection objects (lists) for the attribute 'value' only. e.g
first List - run execution with int a = 1 until finish
second List - run execution with in a = 5 until finish and this time I need to compare the attribute 'value' for the two Lists. ...

let me know if still dont get it....
Shana
Feb 2 '07 #4
r035198x
13,262 8TB
I’m not too sure to answer your Q. What I’ve understood is Yes I have objects of type Entry. First I ran those codes with int a[0] and try to record the attribute value at each IF* bytecode. So the output from this code giving – 4 Entry for first execution.

Expand|Select|Wrap|Line Numbers
  1. Iterator iter = ifs.iterator();
  2.  
  3. while (iter.hasNext()) 
  4.  
  5. {
  6.  
  7. System.out.println(\"string \" + iter.next()); }
  8.  
  9. System.out.print(ifs.size());
  10.  
  11.  
Then I ran again the execution to execute second int a value from array and try to compare the current ifs.value of int a[1] with previous ifs.value of int a[0]. So in short - to compare two Entry of two objects int a[1] and int a[0] using attribute ‘value’ only.
To compare two Entry objects using value only, add a compareTo method in the Entry class which compares the values

Expand|Select|Wrap|Line Numbers
  1.  public int compareTo (Entry e) { 
  2.  
  3. if(value < e.value) {
  4.  
  5.    return -1;
  6.  
  7. }
  8.  
  9. else if(value == 0) {
  10.  
  11.    return 0;
  12.  
  13. }
  14.  
  15. else {
  16.  
  17. return 1;
  18.  
  19. }
  20.  
  21. }
  22.  
  23.  
  24.  
  25.  
Now simply use that method to compare two Entry objects using value only.
Feb 2 '07 #5
shana07
281 100+
Could you please tell me why I got this error?
java.lang.Error: Unresolved compilation problem:
The method compareTo(Object) is undefined for the type TestDriver
I call method compareTo such this:
(as mentioned above I want to compare two Entry objects)
Expand|Select|Wrap|Line Numbers
  1.  void report (String header) 
  2.   {
  3.     final int EQUAL = 0;
  4.     System.out.println(header);
  5.     for (int i = 1; i < ifs.size(); i++) 
  6.     {
  7.        int comparison = compareTo(ifs.get(0));
  8.        if (comparison != EQUAL) 
  9.        {
  10.    System.out.println ();
  11.   System.out.println ("A DIFFERENT BRANCH HAS BEEN FOUND:" +IfCount);
  12.   break;
  13.             }
  14.         else 
  15.         {
  16.     System.out.println ("FAILED TO FIND A DIFFERENT BRANCH:" +IfCount);
  17.     break;
  18.         }       
  19.     } 
Feb 3 '07 #6
shana07
281 100+
Maybe you can help me to explain in short what's actually doing in method 'compareTo' especially when you give return 1 and etc.
Feb 3 '07 #7
r035198x
13,262 8TB
Maybe you can help me to explain in short what's actually doing in method 'compareTo' especially when you give return 1 and etc.
The compareTo method is a method that you are using to compare 2 Entry objects. This can result in three possiblities. the objects might be equal (return 0) the current Object might be less than the given object (return -1) while the other option returns 1. the return values are what we will check to see the result of the comparison.
Feb 3 '07 #8
r035198x
13,262 8TB
Could you please tell me why I got this error?


I call method compareTo such this:
(as mentioned above I want to compare two Entry objects)
Expand|Select|Wrap|Line Numbers
  1. void report (String header) 
  2. {
  3. final int EQUAL = 0;
  4. System.out.println(header);
  5. for (int i = 1; i < ifs.size(); i++) 
  6. {
  7. int comparison = compareTo(ifs.get(0));
  8. if (comparison != EQUAL) 
  9. {
  10. System.out.println ();
  11. System.out.println ("A DIFFERENT BRANCH HAS BEEN FOUND:" +IfCount);
  12. break;
  13. }
  14. else 
  15. {
  16. System.out.println ("FAILED TO FIND A DIFFERENT BRANCH:" +IfCount);
  17. break;
You said you wanted to compare two Entry objects, so you should put the method compareTo inside the Entry class.
Feb 3 '07 #9
shana07
281 100+
Alright in my case, what need to be compared is 'boolean' value. I want to compare (currentobject != previousobject) - in terms of values either both are TRUE/FALSE.
Expand|Select|Wrap|Line Numbers
  1. public int compareTo (Entry e) 
  2.    { 
  3.       if(value != e.value) 
  4.        {
  5.            return -1;
  6.         }
  7.        else if(value == e.value)
  8.        {
  9.            return 0;
  10.        }
  11.        else 
  12.        {
  13.            return 1;
  14.        }
  15.     }  
could you please take a look at the error above....
Feb 3 '07 #10
shana07
281 100+
You said you wanted to compare two Entry objects, so you should put the method compareTo inside the Entry class.
Yes I did put it....
Expand|Select|Wrap|Line Numbers
  1. class Entry
  2. {
  3.    public Object position;
  4.    public boolean value;
  5.  
  6.    public Entry(Object position, boolean value)
  7.  {
  8.      this.position = position;
  9.      this.value    = value;
  10.    }
  11.  
  12.    public int compareTo (Entry e) 
  13.    { 
  14.       if(value != e.value) 
  15.        {
  16.            return -1;
  17.         }
  18.        else if(value == e.value)
  19.        {
  20.            return 0;
  21.        }
  22.        else 
  23.        {
  24.            return 1;
  25.        }
  26.     }  
  27. }
Feb 3 '07 #11
r035198x
13,262 8TB
Yes I did put it....
Expand|Select|Wrap|Line Numbers
  1. class Entry
  2. {
  3. public Object position;
  4. public boolean value;
  5.  
  6. public Entry(Object position, boolean value)
  7. {
  8. this.position = position;
  9. this.value = value;
  10. }
  11.  
  12. public int compareTo (Entry e) 
  13. if(value != e.value) 
  14. {
  15. return -1;
  16. }
  17. else if(value == e.value)
  18. {
  19. return 0;
  20. }
  21. else 
  22. {
  23. return 1;
  24. }
  25. }
If you are using a boolean value for comparison then simply override the equals method
as
Expand|Select|Wrap|Line Numbers
  1.  public boolean equals(Entry e) { 
  2.   return value == e.value;
  3. }
  4.  
The method is in the Entry class, so you call it using an instance of the Entry class.
Something like
Expand|Select|Wrap|Line Numbers
  1.  Entry e = ....... 
  2. if(e.equals(Entry anotherEntry)) {
  3.   //do stuff
  4. }
  5. else {
  6. //do something else
  7.  
calling it in some other class as just equals(e) (like you did with the compareTo) does not make sense and would give incorect results for the equals method and a compilation error for the compareTo method.
Feb 3 '07 #12
shana07
281 100+
Thank you bro...short and clear explanation.
After override with 'equals' and made some adjustment Entry e to Object o (because prompted error something uncompatible Entry - Object...) I got what I want now.
Expand|Select|Wrap|Line Numbers
  1.  Object o = ifs.get(4);
  2.         if(o.equals(ifs.get(0))) 
Thanks a bunch...........
Shana
Feb 3 '07 #13
r035198x
13,262 8TB
Thank you bro...short and clear explanation.
After override with 'equals' and made some adjustment Entry e to Object o (because prompted error something uncompatible Entry - Object...) I got what I want now.
Expand|Select|Wrap|Line Numbers
  1.  Object o = ifs.get(4);
  2. if(o.equals(ifs.get(0))) 
Thanks a bunch...........
Shana
Anytime. It took me a while to understand what you wanted to do there though.
Feb 3 '07 #14
Ganon11
3,652 Expert 2GB
Thank you bro...short and clear explanation.
After override with 'equals' and made some adjustment Entry e to Object o (because prompted error something uncompatible Entry - Object...) I got what I want now.
Expand|Select|Wrap|Line Numbers
  1.  Object o = ifs.get(4);
  2.         if(o.equals(ifs.get(0))) 
Thanks a bunch...........
Shana
You may end up having some loss of information when casting to an Object to compare. Instead, you may want to case ifs.get() to Entry, as in:

Expand|Select|Wrap|Line Numbers
  1. Entry myEnt = (Entry)ifs.get(4);
  2. if (myEnt.equals((Entry)ifs.get(0))) {
  3.    // And so on...
Feb 3 '07 #15
shana07
281 100+
Yes, you're right bro. I noticed it when I tried to track the 'equals' method and it refers to 'equals (Object o)' in java default class. until I changed my code to
Expand|Select|Wrap|Line Numbers
  1.  Entry e = new Entry(14, true );       
  2.        if(e.equals(new Entry(14, true)))
but it's not practical work.

Yes I put your code & it works fine. Also I can choose any entry to compare with. thanks.....
Feb 3 '07 #16
shana07
281 100+
Good Day!
Again, allow me to ask further questions here regarding java.util.List.

1. How if I use an Array rather than List - advantage of using List is?
2 Could anyone gives me some pointers on how to convert List to an Array?
the codes shown above are the one which need to be converted to array.

Teach me on how to get array IF[] to store such information (exactly like what is done in the List above):
Expand|Select|Wrap|Line Numbers
  1. IF[0].position = 
  2. IF[0].value    = 
  3. IF[1].position = 
  4. IF[1].value    = 
  5. ...
  6. IF[n].position = 
  7. IF[n].value    = 
  8.  
  9. if (n<0) 
  10. {
  11.    Print "There is no if bytecode."}
  12. print n;
  13.  
Thank you..........
Feb 6 '07 #17
r035198x
13,262 8TB
Good Day!
Again, allow me to ask further questions here regarding java.util.List.

1. How if I use an Array rather than List - advantage of using List is?
2 Could anyone gives me some pointers on how to convert List to an Array?
the codes shown above are the one which need to be converted to array.

Teach me on how to get array IF[] to store such information (exactly like what is done in the List above):
Expand|Select|Wrap|Line Numbers
  1. IF[0].position = 
  2. IF[0].value = 
  3. IF[1].position = 
  4. IF[1].value = 
  5. ...
  6. IF[n].position = 
  7. IF[n].value = 
  8.  
  9. if (n<0) 
  10. {
  11. Print "There is no if bytecode."}
  12. print n;
  13.  
Thank you..........
You should really be reading the docs for this. You will find the toArray() method there as well.
Feb 6 '07 #18
shana07
281 100+
By putting this code, I managed to get them in an array!
Expand|Select|Wrap|Line Numbers
  1. Object IF[] = ifs.toArray(new Object[ifs.size()]) ;
Thanks to you.....
Shana
Feb 7 '07 #19
r035198x
13,262 8TB
By putting this code, I managed to get them in an array!

Expand|Select|Wrap|Line Numbers
  1. Object IF[] = ifs.toArray(new Object[ifs.size()]) ;
Thanks to you.....

Shana


And thanks to the docs too of course.
Feb 7 '07 #20
shana07
281 100+
Hi Friends, Sorry because I have one more question regarding this topic ;)
I have 2 lists & initialized as:
Expand|Select|Wrap|Line Numbers
  1. java.util.List ifs = new java.util.ArrayList();
  2. java.util.List ifs1 = new java.util.ArrayList();
  3.  
In one method, I convert them to array with variables:
Expand|Select|Wrap|Line Numbers
  1. Object IF[] = ifs.toArray(new Object[ifs.size()]);
  2. Object IF1[] = ifs.toArray(new Object[ifs1.size()]);
  3.  
The first IF[] is main array and its length=4 (only one execution)
IF1[] is supposed to execute in loop which each loop its length is also = 4.
In short:
Array IF1[]:
0 – legth=4
1 – length=4
2 – ..
3 – ..
4 – ..
5 – ..

My questions:
1. How to make IF1[] running in loop?
2. At last after store all arrays, I need to compare 'VALUE' field for each data of arrays IF1[] with IF[]. Teach me how to do this?
Code below gives an idea on what's to compare IF[] & IF1[]
(the code is wrong, its supposed to be array comparisons)
Expand|Select|Wrap|Line Numbers
  1. Entry myEnt = (Entry)ifs1.get(i);          
  2. if(myEnt.equals((Entry)ifs.get(i)))
  3.  { 
  4.     System.out.println ("A" );       
  5.  }
  6.     else 
  7.      {
  8.     System.out.println ("B" );                       
  9.       }  
  10.  
Here is my Entry(): -
Expand|Select|Wrap|Line Numbers
  1. class Entry
  2. {
  3.    public Object position;
  4.    public boolean value;
  5.  
  6.    public Entry(Object position, boolean value)
  7.  {
  8.      this.position = position;
  9.      this.value    = value;    
  10.   }
  11.  
  12.    public boolean equals(Entry e) 
  13.    { 
  14.      return value != e.value;
  15.    }
  16. }
Please advise & many thanks
Feb 13 '07 #21
r035198x
13,262 8TB
Hi Friends, Sorry because I have one more question regarding this topic ;)
I have 2 lists & initialized as:
Expand|Select|Wrap|Line Numbers
  1. java.util.List ifs = new java.util.ArrayList();
  2. java.util.List ifs1 = new java.util.ArrayList();
  3.  
In one method, I convert them to array with variables:
Expand|Select|Wrap|Line Numbers
  1. Object IF[] = ifs.toArray(new Object[ifs.size()]);
  2. Object IF1[] = ifs.toArray(new Object[ifs1.size()]);
  3.  
The first IF[] is main array and its length=4 (only one execution)
IF1[] is supposed to execute in loop which each loop its length is also = 4.
In short:
Array IF1[]:
0 – legth=4
1 – length=4
2 – ..
3 – ..
4 – ..
5 – ..

My questions:
1. How to make IF1[] running in loop?
2. At last after store all arrays, I need to compare 'VALUE' field for each data of arrays IF1[] with IF[]. Teach me how to do this?
Code below gives an idea on what's to compare IF[] & IF1[]
(the code is wrong, its supposed to be array comparisons)
Expand|Select|Wrap|Line Numbers
  1. Entry myEnt = (Entry)ifs1.get(i); 
  2. if(myEnt.equals((Entry)ifs.get(i)))
  3. System.out.println ("A" ); 
  4. }
  5. else 
  6. {
  7. System.out.println ("B" ); 
  8.  
Here is my Entry(): -
Expand|Select|Wrap|Line Numbers
  1. class Entry
  2. {
  3. public Object position;
  4. public boolean value;
  5.  
  6. public Entry(Object position, boolean value)
  7. {
  8. this.position = position;
  9. this.value = value; 
  10. }
  11.  
  12. public boolean equals(Entry e) 
  13. return value != e.value;
  14. }
  15. }
Please advise & many thanks
Expand|Select|Wrap|Line Numbers
  1.  if(IF[i].equals(IF1[i]))
Feb 13 '07 #22
shana07
281 100+
Hi, I've tried & it seems not compare for the VALUE field. it's comparing whole arrays. correct me if i'm wrong. tq
Feb 13 '07 #23
r035198x
13,262 8TB
Hi, I've tried & it seems not compare for the VALUE field. it's comparing whole arrays. correct me if i'm wrong. tq
You mean the Lists contain Arrays? So what do you want to compare?
Feb 13 '07 #24
shana07
281 100+
I was thinking about the need to initialize IF[].value in here?
Which previously you once told me to put equals() in order to compare only VALUE field in Entry class (List).
And now since I do need to use array, how to make this comparison possible.....
Feb 13 '07 #25
r035198x
13,262 8TB
I was thinking about the need to initialize IF[].value in here?
Which previously you once told me to put equals() in order to compare only VALUE field in Entry class (List).
And now since I do need to use array, how to make this comparison possible.....
Ok let's get some things clear here.
IF and IF1 are arrays containing what?
Do they contain Entry objects or are they arrays containing other arrays inside them?
Feb 13 '07 #26
shana07
281 100+
You mean the Lists contain Arrays? So what do you want to compare?
Pretty understand your confusion. my blunder!
1. I'm not sure either still need to use Lists in here.
2. What I want to compare is only 'value' field in those arrays like this.
Expand|Select|Wrap|Line Numbers
  1.   public boolean equals(Entry e) 
  2.    { 
  3.      return value != e.value;
  4.    }
The Lists:
Expand|Select|Wrap|Line Numbers
  1. ifs.add(new Entry(position, value)); 
  2.  ifs1.add(new Entry(position, value));
Feb 13 '07 #27
shana07
281 100+
Ok let's get some things clear here.
IF and IF1 are arrays containing what?
Do they contain Entry objects or are they arrays containing other arrays inside them?
IF & IF1 arrays suppose to contain Entry objects: Please check this code (only for IF) which I was thinking I already put them into Array :
Expand|Select|Wrap|Line Numbers
  1. IfInstruction iff = (IfInstruction) insn;
  2.  Object IF[] = ifs.toArray(new Object[ifs.size()]) ;
  3.   Object position = insn.getOffset();
  4.  
  5.   boolean value = iff.getConditionValue();
  6.    value = ! value;
  7.  ifs.add(new Entry(position, value));
  8.    System.out.println("IF.position: " +position);
  9.  System.out.println("IF.value: " +value); 
My aim is to put such this in array:
IF[0].position
IF[0].value
IF[1].position
.....
....
IF[3].position
IF[3].value
Feb 13 '07 #28
r035198x
13,262 8TB
Pretty understand your confusion. my blunder!
1. I'm not sure either still need to use Lists in here.
2. What I want to compare is only 'value' field in those arrays like this.
Expand|Select|Wrap|Line Numbers
  1.  public boolean equals(Entry e) 
  2. return value != e.value;
  3. }
The Lists:
Expand|Select|Wrap|Line Numbers
  1. ifs.add(new Entry(position, value)); 
  2. ifs1.add(new Entry(position, value));
The code that adds Entries to the lists shows that the Arrays IF and IF1 contain Entry objects so comparing their entries with IF[i].equals(IF1[i]) actually compares entries using their values. Is that what you want?
Feb 13 '07 #29
shana07
281 100+
The code that adds Entries to the lists shows that the Arrays IF and IF1 contain Entry objects so comparing their entries with IF[i].equals(IF1[i]) actually compares entries using their values. Is that what you want?
From what I understand your question is yes!
But if I track the 'equals' method declaration from my netbeans, it's not pointed to 'equals' what we put in the Entry class. It points to 'equals' in java/lang/Object.java(r/o) .
Maybe that's the reason why I don't get right comparison answer
Feb 13 '07 #30
r035198x
13,262 8TB
From what I understand your question is yes!
But if I track the 'equals' method declaration from my netbeans, it's not pointed to 'equals' what we put in the Entry class. It points to 'equals' in java/lang/Object.java(r/o) .
Maybe that's the reason why I don't get right comparison answer
That's because we did not override the equals method. Instead we overloaded the equals method with another. Change that equals method's signature to
Expand|Select|Wrap|Line Numbers
  1.  public boolean equals(Object e)
Feb 13 '07 #31
shana07
281 100+
That's because we did not override the equals method. Instead we overloaded the equals method with another. Change that equals method's signature to
Expand|Select|Wrap|Line Numbers
  1.  public boolean equals(Object e)
Expand|Select|Wrap|Line Numbers
  1.  cannot find symbol
  2.     [javac] symbol  : variable value
  3.     [javac] location: class java.lang.Object
  4.     [javac] return value != e.value;
  5. java.lang.Error: Unresolved compilation problem: 
  6.     e.value cannot be resolved or is not a field
  7.  
Feb 13 '07 #32
r035198x
13,262 8TB
Expand|Select|Wrap|Line Numbers
  1.  cannot find symbol
  2. [javac] symbol : variable value
  3. [javac] location: class java.lang.Object
  4. [javac] return value != e.value;
  5. java.lang.Error: Unresolved compilation problem: 
  6.     e.value cannot be resolved or is not a field
  7.  
You'd of course then have to type cast the Object to Event to make that work.

Expand|Select|Wrap|Line Numbers
  1.  public boolean equals(Object e) { 
  2.  Event event = (Event)e;
  3. ......
  4.  
Feb 13 '07 #33
shana07
281 100+
sorry, I still don't get the right answer.
I'll update again. thanks for your help.
Feb 13 '07 #34
r035198x
13,262 8TB
sorry, I still don\'t get the right answer.

I\'ll update again. thanks for your help.
Like this

Expand|Select|Wrap|Line Numbers
  1.  public boolean equals(Object e) 
  2.  
  3.  return value != ((Entry)e).value;
  4. }
  5.  
  6.  


What errors are you still getting?
Feb 13 '07 #35
shana07
281 100+
dear friend,
your code works fine.TQ.
Take a look at this it seems mine & yours not much different at glance..hurm
Expand|Select|Wrap|Line Numbers
  1. public boolean equals(Object e)  
  2.    { 
  3.       Entry entry = (Entry)e;          
  4.       return value != entry.value;    
  5.    }
  6.  
  7.     public boolean equals(Object e) 
  8.     { 
  9.      return value != ((Entry)e).value;
  10.     }
Feb 14 '07 #36
shana07
281 100+
Friend,
I have other doubt about Lists..please advise.
Is it possible for me to get a Lists with many sub_Lists?
Meaning, under same 'ifs1' field has many ifs1[i], ifs1[2] and etc....Take a look at this:
Expand|Select|Wrap|Line Numbers
  1. java.util.List ifs = new java.util.ArrayList(); ---> this field with ifs.size()=4 and no change.
  2.  
  3. java.util.List ifs1 = new java.util.ArrayList(); ---> this field with ifs1[i].size()=4
  4. ifs1[ii].size=4, .......will increase more & more.
  5.  
The reason why i'm getting this because
1. I want to make sure/remain the size for ifs1 & 'ifs' is SAME (4)

At this moment, I don't think about the need to create more Lists (because it can be too many Lists),
if you think that I do need, then how to get that in efficient way....thank u
Feb 14 '07 #37
r035198x
13,262 8TB
dear friend,
your code works fine.TQ.
Take a look at this it seems mine & yours not much different at glance..hurm
Expand|Select|Wrap|Line Numbers
  1. public boolean equals(Object e) 
  2. Entry entry = (Entry)e; 
  3. return value != entry.value; 
  4. }
  5.  
  6. public boolean equals(Object e) 
  7. return value != ((Entry)e).value;
  8. }
Both should work the same way.
Feb 14 '07 #38
shana07
281 100+
Both should work the same way.
Noted. Could you please take a look at my above post. I have other doubt about this Lists please.
Feb 14 '07 #39
r035198x
13,262 8TB
Friend,
I have other doubt about Lists..please advise.
Is it possible for me to get a Lists with many sub_Lists?
Meaning, under same 'ifs1' field has many ifs1[i], ifs1[2] and etc....Take a look at this:
Expand|Select|Wrap|Line Numbers
  1. java.util.List ifs = new java.util.ArrayList(); ---> this field with ifs.size()=4 and no change.
  2.  
  3. java.util.List ifs1 = new java.util.ArrayList(); ---> this field with ifs1[i].size()=4
  4. ifs1[ii].size=4, .......will increase more & more.
  5.  
The reason why i'm getting this because
1. I want to make sure/remain the size for ifs1 & 'ifs' is SAME (4)

At this moment, I don't think about the need to create more Lists (because it can be too many Lists),
if you think that I do need, then how to get that in efficient way....thank u
I'll be frank here. I did not understand all that. All I can say is an ArrayList can contain other lists as elements as well.

Expand|Select|Wrap|Line Numbers
  1.  ArrayList list = new ArrayList(); 
  2. list(0) = new ArrayList();
  3.  
Or
Expand|Select|Wrap|Line Numbers
  1. ArrayList<ArrayList> lists = new ArrayList<ArrayList>();
Feb 14 '07 #40
shana07
281 100+
I'll be frank here. I did not understand all that. All I can say is an ArrayList can contain other lists as elements as well.

Expand|Select|Wrap|Line Numbers
  1.  ArrayList list = new ArrayList(); 
  2. list(0) = new ArrayList();
  3.  
Or
Expand|Select|Wrap|Line Numbers
  1. ArrayList<ArrayList> lists = new ArrayList<ArrayList>();
:) at least thanks for reading my problem.

From the code, what's mean for list[0]?
How about these codes, what's the difference?
Expand|Select|Wrap|Line Numbers
  1.  List ifs = new ArrayList();  vs.  ArrayList ifs = new ArrayList(); 
If you have an example how to use the ArrayList, please share with me.
Feb 14 '07 #41
r035198x
13,262 8TB
:) at least thanks for reading my problem.

From the code, what's mean for list[0]?
How about these codes, what's the difference?
Expand|Select|Wrap|Line Numbers
  1.  List ifs = new ArrayList(); vs. ArrayList ifs = new ArrayList(); 
If you have an example how to use the ArrayList, please share with me.
Expand|Select|Wrap|Line Numbers
  1. List ifs = new ArrayList(); 
the ArrayList is stored in a variable of type List. Any calls to static variables call variables in the List interface. You can also assign other type of Lists e.g LinkedList to be stored by the variable ifs whereas with
Expand|Select|Wrap|Line Numbers
  1. ArrayList ifs = new ArrayList(); 
you cannot make ifs store a reference to any object of type that is not a subclass of ArrayList. You'll probably not be able to notice the difference.
Feb 14 '07 #42
shana07
281 100+
Expand|Select|Wrap|Line Numbers
  1. List ifs = new ArrayList(); 
the ArrayList is stored in a variable of type List. Any calls to static variables call variables in the List interface. You can also assign other type of Lists e.g LinkedList to be stored by the variable ifs whereas with
Expand|Select|Wrap|Line Numbers
  1. ArrayList ifs = new ArrayList(); 
you cannot make ifs store a reference to any object of type that is not a subclass of ArrayList. You'll probably not be able to notice the difference.
I've tried run program by replacing
Expand|Select|Wrap|Line Numbers
  1. ArrayList ifs1 = new java.util.ArrayList();
in my program, yes I can't see the difference. the entries are the same.
you cannot make ifs store a reference to any object of type that is not a subclass of ArrayList.
What's the subclass here mean?
Feb 14 '07 #43
r035198x
13,262 8TB
I've tried run program by replacing
Expand|Select|Wrap|Line Numbers
  1. ArrayList ifs1 = new java.util.ArrayList();
in my program, yes I can't see the difference. the entries are the same.
you cannot make ifs store a reference to any object of type that is not a subclass of ArrayList.
What's the subclass here mean?
A class that inherits from the class ArrayList. (That's if you know any inheritance)

if you have
Expand|Select|Wrap|Line Numbers
  1.  class B { 
  2. }
  3.  
and
Expand|Select|Wrap|Line Numbers
  1.  class A extends B { 
  2. }
  3.  
You can do
Expand|Select|Wrap|Line Numbers
  1. B b = new A();
but you cannot do
Expand|Select|Wrap|Line Numbers
  1.  A a = new B();
In this case your B is list and your A is ArrayList except for that List is actually an interface rather than a class.
Feb 14 '07 #44
shana07
281 100+
A class that inherits from the class ArrayList. (That's if you know any inheritance)
if you have
Expand|Select|Wrap|Line Numbers
  1.  class B { 
  2. }
  3.  
and
Expand|Select|Wrap|Line Numbers
  1.  class A extends B { 
  2. }
  3.  
You can do
Expand|Select|Wrap|Line Numbers
  1. B b = new A();
but you cannot do
Expand|Select|Wrap|Line Numbers
  1.  A a = new B();
In this case your B is list and your A is ArrayList except for that List is actually an interface rather than a class.
TQ.Pretty understood List now and also I read List is an interface from a Collection.
Then, how about an ArrayList can contain other lists .....as what you said?
[quote=r035198x] All I can say is an ArrayList can contain other lists as elements as well.
Expand|Select|Wrap|Line Numbers
  1.  ArrayList list = new ArrayList(); 
  2. list(0) = new ArrayList();
  3.  
Coz, my aim here is to create many ArrayList (or list - not sure) with the same variable (ifs1) in loop.
again, not sure this is possible or not.....
Feb 14 '07 #45
r035198x
13,262 8TB
[quote=shana07]TQ.Pretty understood List now and also I read List is an interface from a Collection.
Then, how about an ArrayList can contain other lists .....as what you said?
All I can say is an ArrayList can contain other lists as elements as well.
Expand|Select|Wrap|Line Numbers
  1.  ArrayList list = new ArrayList(); 
  2. list(0) = new ArrayList();
  3.  
Coz, my aim here is to create many ArrayList (or list - not sure) with the same variable (ifs1) in loop.
again, not sure this is possible or not.....
If you want to create many ArrayLists (they are also lists since ArrayList implements List) then just do as I posted earlier

either
Expand|Select|Wrap|Line Numbers
  1. ArrayList<ArrayList> lists = new ArrayList<ArrayList>(); //preferrable
or
Expand|Select|Wrap|Line Numbers
  1.  ArrayList lists = new ArrayList();
Then add the lists at their positions with
Expand|Select|Wrap|Line Numbers
  1.  lists(i) = new ArrayList(); 
Feb 14 '07 #46
shana07
281 100+
Expand|Select|Wrap|Line Numbers
  1. ArrayList<ArrayList> ifs1 = new ArrayList<ArrayList>(); //preferrable
found an error:
java.util.ArrayList does not take parameters

Expand|Select|Wrap|Line Numbers
  1. ArrayList ifs1 = new java.util.ArrayList();
  2. ......
  3. int ch = getNumber();
  4. ifs1(ch) = new ArrayList();    
error: cannot find symbol
symbol : method ifs1(int)
Feb 14 '07 #47
r035198x
13,262 8TB
Expand|Select|Wrap|Line Numbers
  1. ArrayList<ArrayList> ifs1 = new ArrayList<ArrayList>(); //preferrable
found an error:

java.util.ArrayList does not take parameters



Expand|Select|Wrap|Line Numbers
  1. ArrayList ifs1 = new java.util.ArrayList();
  2.  
  3. ......
  4.  
  5. int ch = getNumber();
  6.  
  7. ifs1(ch) = new ArrayList(); 
error: cannot find symbol

symbol : method ifs1(int)


Yeah it is supposed to be

Expand|Select|Wrap|Line Numbers
  1.  ArrayList list = new ArrayList(); 
  2.  
  3. ifs1.set(index, list); 
  4.  
  5.  
Feb 14 '07 #48
shana07
281 100+
just to let you know I'm still working on it..by the way,
making such code, how's the result should I get..
is that creating more ArrayList using ifs1 variable?
Feb 14 '07 #49

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

Similar topics

73
by: RobertMaas | last post by:
After many years of using LISP, I'm taking a class in Java and finding the two roughly comparable in some ways and very different in other ways. Each has a decent size library of useful utilities...
4
by: angel | last post by:
A java runtime environment includes jvm and java class (for example classes.zip in sun jre). Of course jython need jvm,but does it need java class. Thanx
4
by: 3rdshiftcoder | last post by:
Hi- I'd like to use this class from a book but am getting a compiler error. On the line private List < String > list; p.932 Chapter 19 found in the code below in the eclipse editor it is...
0
by: daniel li | last post by:
I got another convert issue. This is the same project as I posted yesterday, and received a perfect response. The conversion threw a SupportClass for me and one of the data type is...
5
by: Egghead | last post by:
Hi, Does anyone know if there is any C#'s class equivalent to java.utl.Vector? I think the System.Collections.ArrayList is not the same: In java: for(int i = 0; i<myVector.length;i++) {...
0
by: Limpor | last post by:
Hello, I am new to learning java, and i am trying to build the class for a calculation card game, unfortunately i can't get the public Card top() and Card takeTop() method in the Stock class. Can...
0
by: jaywak | last post by:
Just tried running some code on Linux (2.4.21-32.0.1.EL and Java(TM) 2 Runtime Environment, Standard Edition (build 1.5.0_04-b05)) and Windows XPSP2 (with Java HotSpot(TM) Client VM (build...
15
by: Xah Lee | last post by:
On Java's Interface Xah Lee, 20050223 In Java the language, there's this a keyword “interface”. In a functional language, a function can be specified by its name and parameter specs....
7
by: svpriyan | last post by:
Dear Buddies, I have two Java Prog: My task is to read the Content of the file and write to an XML file. so i started doing it perfectly... What i have problem is when i tried to execute the...
2
by: yeshello54 | last post by:
so here is my problem...in a contact manager i am trying to complete i have ran into an error..we have lots of code because we have some from class which we can use...anyways i keep getting an error...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

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.