Hi again, would like to consult about List problem.
//start code - java.util.List ifs = new java.util.ArrayList();
-
// we're in the 'getMonitor' method -
Instruction insn = jvm.getLastInstruction();
-
………
-
………
-
if (insn instanceof IfInstruction)
-
{
-
IfInstruction iff = (IfInstruction) insn;
-
Object position = insn.getOffset();
-
boolean value = iff.getConditionValue();
-
ifs.add(new Entry(position, value));
-
-
System.out.print(position);
-
System.out.println();
-
System.out.print(value);
-
System.out.println();
-
-
Iterator iter = ifs.iterator();
-
while (iter.hasNext()) {
-
System.out.println("string " + iter.next());
-
}
-
System.out.print(ifs.size());
-
System.out.println();
-
}
-
// ... the rest of the method are here
-
- class Entry {
-
public Object position;
-
public boolean value;
-
-
public Entry(Object position, boolean value) {
-
this.position = position;
-
this.value = value;
-
}
-
}
-
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. - void report( )
-
………
-
………
-
//ifs.get(1) != ifs.get(0)
-
//I don't need this because it is getting compare the
-
//whole Entry.I need something like this:
-
-
if (ifs.value(1) != ifs.value(0)) //For sure errors encountered!
-
{
-
System.out.println (“A”);
-
}
-
else
-
{
-
System.out.println (“B”);
-
}
-
Please advise me. thanks guys...
48 4540
Hi again, would like to consult about List problem.
//start code - java.util.List ifs = new java.util.ArrayList();
-
// we're in the 'getMonitor' method -
Instruction insn = jvm.getLastInstruction();
-
………
-
………
-
if (insn instanceof IfInstruction)
-
{
-
IfInstruction iff = (IfInstruction) insn;
-
Object position = insn.getOffset();
-
boolean value = iff.getConditionValue();
-
ifs.add(new Entry(position, value));
-
-
System.out.print(position);
-
System.out.println();
-
System.out.print(value);
-
System.out.println();
-
-
Iterator iter = ifs.iterator();
-
while (iter.hasNext()) {
-
System.out.println("string " + iter.next());
-
}
-
System.out.print(ifs.size());
-
System.out.println();
-
}
-
// ... the rest of the method are here
-
- class Entry {
-
public Object position;
-
public boolean value;
-
-
public Entry(Object position, boolean value) {
-
this.position = position;
-
this.value = value;
-
}
-
}
-
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. - void report( )
-
………
-
………
-
//ifs.get(1) != ifs.get(0)
-
//I don't need this because it is getting compare the
-
//whole Entry.I need something like this:
-
-
if (ifs.value(1) != ifs.value(0)) //For sure errors encountered!
-
{
-
System.out.println (“A”);
-
}
-
else
-
{
-
System.out.println (“B”);
-
}
-
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?
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. - Iterator iter = ifs.iterator();
-
while (iter.hasNext())
-
{
-
System.out.println("string " + iter.next()); }
-
System.out.print(ifs.size());
-
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.
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
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. - Iterator iter = ifs.iterator();
-
-
while (iter.hasNext())
-
-
{
-
-
System.out.println(\"string \" + iter.next()); }
-
-
System.out.print(ifs.size());
-
-
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 - public int compareTo (Entry e) {
-
-
if(value < e.value) {
-
-
return -1;
-
-
}
-
-
else if(value == 0) {
-
-
return 0;
-
-
}
-
-
else {
-
-
return 1;
-
-
}
-
-
}
-
-
-
-
Now simply use that method to compare two Entry objects using value only.
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) -
void report (String header)
-
{
-
final int EQUAL = 0;
-
System.out.println(header);
-
for (int i = 1; i < ifs.size(); i++)
-
{
-
int comparison = compareTo(ifs.get(0));
-
if (comparison != EQUAL)
-
{
-
System.out.println ();
-
System.out.println ("A DIFFERENT BRANCH HAS BEEN FOUND:" +IfCount);
-
break;
-
}
-
else
-
{
-
System.out.println ("FAILED TO FIND A DIFFERENT BRANCH:" +IfCount);
-
break;
-
}
-
}
Maybe you can help me to explain in short what's actually doing in method 'compareTo' especially when you give return 1 and etc.
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.
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) -
void report (String header)
-
{
-
final int EQUAL = 0;
-
System.out.println(header);
-
for (int i = 1; i < ifs.size(); i++)
-
{
-
int comparison = compareTo(ifs.get(0));
-
if (comparison != EQUAL)
-
{
-
System.out.println ();
-
System.out.println ("A DIFFERENT BRANCH HAS BEEN FOUND:" +IfCount);
-
break;
-
}
-
else
-
{
-
System.out.println ("FAILED TO FIND A DIFFERENT BRANCH:" +IfCount);
-
break;
-
}
-
}
You said you wanted to compare two Entry objects, so you should put the method compareTo inside the Entry class.
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. - public int compareTo (Entry e)
-
{
-
if(value != e.value)
-
{
-
return -1;
-
}
-
else if(value == e.value)
-
{
-
return 0;
-
}
-
else
-
{
-
return 1;
-
}
-
}
could you please take a look at the error above....
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.... - class Entry
-
{
-
public Object position;
-
public boolean value;
-
-
public Entry(Object position, boolean value)
-
{
-
this.position = position;
-
this.value = value;
-
}
-
-
public int compareTo (Entry e)
-
{
-
if(value != e.value)
-
{
-
return -1;
-
}
-
else if(value == e.value)
-
{
-
return 0;
-
}
-
else
-
{
-
return 1;
-
}
-
}
-
}
Yes I did put it.... - class Entry
-
{
-
public Object position;
-
public boolean value;
-
-
public Entry(Object position, boolean value)
-
{
-
this.position = position;
-
this.value = value;
-
}
-
-
public int compareTo (Entry e)
-
{
-
if(value != e.value)
-
{
-
return -1;
-
}
-
else if(value == e.value)
-
{
-
return 0;
-
}
-
else
-
{
-
return 1;
-
}
-
}
-
}
If you are using a boolean value for comparison then simply override the equals method
as - public boolean equals(Entry e) {
-
return value == e.value;
-
}
-
The method is in the Entry class, so you call it using an instance of the Entry class.
Something like - Entry e = .......
-
if(e.equals(Entry anotherEntry)) {
-
//do stuff
-
}
-
else {
-
//do something else
-
}
-
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.
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. - Object o = ifs.get(4);
-
if(o.equals(ifs.get(0)))
Thanks a bunch...........
Shana
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. - Object o = ifs.get(4);
-
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.
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. - Object o = ifs.get(4);
-
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: - Entry myEnt = (Entry)ifs.get(4);
-
if (myEnt.equals((Entry)ifs.get(0))) {
-
// And so on...
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 - Entry e = new Entry(14, true );
-
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.....
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): -
IF[0].position =
-
IF[0].value =
-
IF[1].position =
-
IF[1].value =
-
...
-
IF[n].position =
-
IF[n].value =
-
-
if (n<0)
-
{
-
Print "There is no if bytecode."}
-
print n;
-
Thank you..........
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): -
IF[0].position =
-
IF[0].value =
-
IF[1].position =
-
IF[1].value =
-
...
-
IF[n].position =
-
IF[n].value =
-
-
if (n<0)
-
{
-
Print "There is no if bytecode."}
-
print n;
-
Thank you..........
You should really be reading the docs for this. You will find the toArray() method there as well.
By putting this code, I managed to get them in an array! - Object IF[] = ifs.toArray(new Object[ifs.size()]) ;
Thanks to you.....
Shana
By putting this code, I managed to get them in an array! - Object IF[] = ifs.toArray(new Object[ifs.size()]) ;
Thanks to you.....
Shana
And thanks to the docs too of course.
Hi Friends, Sorry because I have one more question regarding this topic ;)
I have 2 lists & initialized as: - java.util.List ifs = new java.util.ArrayList();
-
java.util.List ifs1 = new java.util.ArrayList();
-
In one method, I convert them to array with variables: - Object IF[] = ifs.toArray(new Object[ifs.size()]);
-
Object IF1[] = ifs.toArray(new Object[ifs1.size()]);
-
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) -
Entry myEnt = (Entry)ifs1.get(i);
-
if(myEnt.equals((Entry)ifs.get(i)))
-
{
-
System.out.println ("A" );
-
}
-
else
-
{
-
System.out.println ("B" );
-
}
-
Here is my Entry(): - - class Entry
-
{
-
public Object position;
-
public boolean value;
-
-
public Entry(Object position, boolean value)
-
{
-
this.position = position;
-
this.value = value;
-
}
-
-
public boolean equals(Entry e)
-
{
-
return value != e.value;
-
}
-
}
Please advise & many thanks
Hi Friends, Sorry because I have one more question regarding this topic ;)
I have 2 lists & initialized as: - java.util.List ifs = new java.util.ArrayList();
-
java.util.List ifs1 = new java.util.ArrayList();
-
In one method, I convert them to array with variables: - Object IF[] = ifs.toArray(new Object[ifs.size()]);
-
Object IF1[] = ifs.toArray(new Object[ifs1.size()]);
-
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) -
Entry myEnt = (Entry)ifs1.get(i);
-
if(myEnt.equals((Entry)ifs.get(i)))
-
{
-
System.out.println ("A" );
-
}
-
else
-
{
-
System.out.println ("B" );
-
}
-
Here is my Entry(): - - class Entry
-
{
-
public Object position;
-
public boolean value;
-
-
public Entry(Object position, boolean value)
-
{
-
this.position = position;
-
this.value = value;
-
}
-
-
public boolean equals(Entry e)
-
{
-
return value != e.value;
-
}
-
}
Please advise & many thanks
Hi, I've tried & it seems not compare for the VALUE field. it's comparing whole arrays. correct me if i'm wrong. tq
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?
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.....
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?
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. - public boolean equals(Entry e)
-
{
-
return value != e.value;
-
}
The Lists: - ifs.add(new Entry(position, value));
-
ifs1.add(new Entry(position, value));
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 : -
IfInstruction iff = (IfInstruction) insn;
-
Object IF[] = ifs.toArray(new Object[ifs.size()]) ;
-
Object position = insn.getOffset();
-
-
boolean value = iff.getConditionValue();
-
value = ! value;
-
ifs.add(new Entry(position, value));
-
System.out.println("IF.position: " +position);
-
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
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. - public boolean equals(Entry e)
-
{
-
return value != e.value;
-
}
The Lists: - ifs.add(new Entry(position, value));
-
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?
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
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 - public boolean equals(Object e)
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 - public boolean equals(Object e)
- cannot find symbol
-
[javac] symbol : variable value
-
[javac] location: class java.lang.Object
-
[javac] return value != e.value;
-
java.lang.Error: Unresolved compilation problem:
-
e.value cannot be resolved or is not a field
-
- cannot find symbol
-
[javac] symbol : variable value
-
[javac] location: class java.lang.Object
-
[javac] return value != e.value;
-
java.lang.Error: Unresolved compilation problem:
-
e.value cannot be resolved or is not a field
-
You'd of course then have to type cast the Object to Event to make that work. - public boolean equals(Object e) {
-
Event event = (Event)e;
-
......
-
sorry, I still don't get the right answer.
I'll update again. thanks for your help.
sorry, I still don\'t get the right answer.
I\'ll update again. thanks for your help.
Like this - public boolean equals(Object e)
-
{
-
-
return value != ((Entry)e).value;
-
}
-
-
What errors are you still getting?
dear friend,
your code works fine.TQ.
Take a look at this it seems mine & yours not much different at glance..hurm - public boolean equals(Object e)
-
{
-
Entry entry = (Entry)e;
-
return value != entry.value;
-
}
-
-
public boolean equals(Object e)
-
{
-
return value != ((Entry)e).value;
-
}
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: -
java.util.List ifs = new java.util.ArrayList(); ---> this field with ifs.size()=4 and no change.
-
-
java.util.List ifs1 = new java.util.ArrayList(); ---> this field with ifs1[i].size()=4
-
ifs1[ii].size=4, .......will increase more & more.
-
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
dear friend,
your code works fine.TQ.
Take a look at this it seems mine & yours not much different at glance..hurm - public boolean equals(Object e)
-
{
-
Entry entry = (Entry)e;
-
return value != entry.value;
-
}
-
-
public boolean equals(Object e)
-
{
-
return value != ((Entry)e).value;
-
}
Both should work the same way.
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.
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: -
java.util.List ifs = new java.util.ArrayList(); ---> this field with ifs.size()=4 and no change.
-
-
java.util.List ifs1 = new java.util.ArrayList(); ---> this field with ifs1[i].size()=4
-
ifs1[ii].size=4, .......will increase more & more.
-
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. - ArrayList list = new ArrayList();
-
list(0) = new ArrayList();
-
Or - ArrayList<ArrayList> lists = new ArrayList<ArrayList>();
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. - ArrayList list = new ArrayList();
-
list(0) = new ArrayList();
-
Or - 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? - List ifs = new ArrayList(); vs. ArrayList ifs = new ArrayList();
If you have an example how to use the ArrayList, please share with me.
:) at least thanks for reading my problem.
From the code, what's mean for list[0]?
How about these codes, what's the difference? - List ifs = new ArrayList(); vs. ArrayList ifs = new ArrayList();
If you have an example how to use the ArrayList, please share with me.
- 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 - 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.
- 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 - 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 - 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?
I've tried run program by replacing - 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
and
You can do
but you cannot do
In this case your B is list and your A is ArrayList except for that List is actually an interface rather than a class.
A class that inherits from the class ArrayList. (That's if you know any inheritance)
if you have
and
You can do
but you cannot do
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. - ArrayList list = new ArrayList();
-
list(0) = new ArrayList();
-
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.....
[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.
- ArrayList list = new ArrayList();
-
list(0) = new ArrayList();
-
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 - ArrayList<ArrayList> lists = new ArrayList<ArrayList>(); //preferrable
or - ArrayList lists = new ArrayList();
Then add the lists at their positions with - lists(i) = new ArrayList();
- ArrayList<ArrayList> ifs1 = new ArrayList<ArrayList>(); //preferrable
found an error:
java.util.ArrayList does not take parameters - ArrayList ifs1 = new java.util.ArrayList();
-
......
-
int ch = getNumber();
-
ifs1(ch) = new ArrayList();
error: cannot find symbol
symbol : method ifs1(int)
- ArrayList<ArrayList> ifs1 = new ArrayList<ArrayList>(); //preferrable
found an error:
java.util.ArrayList does not take parameters - ArrayList ifs1 = new java.util.ArrayList();
-
-
......
-
-
int ch = getNumber();
-
-
ifs1(ch) = new ArrayList();
error: cannot find symbol
symbol : method ifs1(int)
Yeah it is supposed to be - ArrayList list = new ArrayList();
-
-
ifs1.set(index, list);
-
-
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?
Sign in to post your reply or Sign up for a free account.
Similar topics
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...
|
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
|
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...
|
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...
|
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++)
{...
|
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...
|
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...
|
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....
|
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...
|
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...
|
by: Charles Arthur |
last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
|
by: nemocccc |
last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
|
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...
|
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...
|
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,...
|
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...
|
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,...
|
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...
|
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,...
| |