Results 1 to 8 of 8
Thread: for each prob
- 05-21-2008, 09:16 AM #1
Member
- Join Date
- May 2008
- Posts
- 3
- Rep Power
- 0
for each prob
Hi i do have problem with this code can any body help me out regarding
public class Main implements Comparable {
public String drink;
public int compareTo(Object o) {
return 0;
}
public static void main(String[] a) {
Main mn1 = new Main();
Main mn2 = new Main();
mn1.drink = "tea";
mn2.drink = "cafe";
TreeSet tree = new TreeSet();
tree.add(mn1);
tree.add(mn2);
////////////////////error block/////////
for(Main m : tree){ types incompatible
//////////////////eb////////////////////
System.out.print(m.drink);
}
}
}
- 05-21-2008, 09:19 AM #2
- Join Date
- Jul 2007
- Location
- Colombo, Sri Lanka
- Posts
- 11,370
- Blog Entries
- 1
- Rep Power
- 26
For loop definition is wrong. What you really want to do. Give more details about your application.
- 05-21-2008, 10:02 AM #3
Member
- Join Date
- May 2008
- Posts
- 3
- Rep Power
- 0
I am just executing the SCJP Qs
here i want to iterate each set and want to print the name of each drink.
- 05-21-2008, 01:34 PM #4
I think you may need to change this to:
Java Code:for(String m : tree){ }
Did this post help you? Pleaseme! :cool:
- 05-21-2008, 01:39 PM #5
- Join Date
- Jul 2007
- Location
- Colombo, Sri Lanka
- Posts
- 11,370
- Blog Entries
- 1
- Rep Power
- 26
I don't think so. Again there is incompatible variables found. Isn't it?
- 05-21-2008, 01:47 PM #6I don't think so. Again there is incompatible variables found. Isn't it?
'Cannot convert from element type Object to main'Did this post help you? Pleaseme! :cool:
- 05-21-2008, 01:57 PM #7
Member
- Join Date
- May 2008
- Posts
- 3
- Rep Power
- 0
I've one more q to get clarified,
Diff btwn
Integer i = 0;
int i=0;
when we do ++i ,i++// in both cases result is diff
why is that so
- 05-21-2008, 02:00 PM #8
++i is pre increment
and
i++ is post increment.
Take a look at this:
Incremental JavaDid this post help you? Pleaseme! :cool:
Similar Threads
-
Need help on a strange file access prob
By squad in forum Advanced JavaReplies: 0Last Post: 03-21-2008, 11:55 AM -
Prob with an exercise
By jhetfield18 in forum New To JavaReplies: 4Last Post: 02-15-2008, 07:11 PM -
Threading prob..
By banie in forum Java AppletsReplies: 0Last Post: 02-05-2008, 07:30 AM -
having prob with Exception
By eva in forum New To JavaReplies: 1Last Post: 01-04-2008, 06:44 PM
Bookmarks