Results 1 to 8 of 8
Thread: for each prob
- 05-21-2008, 08: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, 08:19 AM #2
- Join Date
- Jul 2007
- Location
- Colombo, Sri Lanka
- Posts
- 11,374
- Blog Entries
- 1
- Rep Power
- 18
For loop definition is wrong. What you really want to do. Give more details about your application.
- 05-21-2008, 09: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, 12:34 PM #4
I think you may need to change this to:
I haven't tested it though. Let me know what happens.Java Code:for(String m : tree){ }Did this post help you? Please
me! :cool:
- 05-21-2008, 12:39 PM #5
- Join Date
- Jul 2007
- Location
- Colombo, Sri Lanka
- Posts
- 11,374
- Blog Entries
- 1
- Rep Power
- 18
I don't think so. Again there is incompatible variables found. Isn't it?
- 05-21-2008, 12:47 PM #6
Like I said I didnt actually test it but your right. After looking at it further this will actually still cause an error.I 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? Please
me! :cool:
- 05-21-2008, 12: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, 01:00 PM #8
++i is pre increment
and
i++ is post increment.
Take a look at this:
Incremental JavaDid this post help you? Please
me! :cool:
Similar Threads
-
Need help on a strange file access prob
By squad in forum Advanced JavaReplies: 0Last Post: 03-21-2008, 10:55 AM -
Prob with an exercise
By jhetfield18 in forum New To JavaReplies: 4Last Post: 02-15-2008, 06:11 PM -
Threading prob..
By banie in forum Java AppletsReplies: 0Last Post: 02-05-2008, 06:30 AM -
having prob with Exception
By eva in forum New To JavaReplies: 1Last Post: 01-04-2008, 05:44 PM


LinkBack URL
About LinkBacks
Reply With Quote
Bookmarks