Java Forums

Main Menu
Home
Today's Posts
FAQ
Search
Contact Us

Java Network
Linux Archive
Java Tips
Java Tips Blog

Sponsored Links





Welcome to the Java Forums.

You are currently viewing our boards as a guest which gives you limited access to view most discussions and access our other features. By joining our free community, you will:

  • have access to post topics
  • communicate privately with other members (PM)
  • not see advertisements between posts
  • have the possibility to earn one of our surprises if you are an active member
  • access many other special features that will be introduced later.

Registration is fast, simple and absolutely free so please, join our community today!

If you have any problems with the registration process or your account login, please contact us.

Reply
 
LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 05-21-2008, 10:16 AM
Member
 
Join Date: May 2008
Posts: 3
kusumathatavarthi is on a distinguished road
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);
}

}
}
Bookmark Post in Technorati
Reply With Quote
Sponsored Links
  #2 (permalink)  
Old 05-21-2008, 10:19 AM
Eranga's Avatar
Moderator
 
Join Date: Jul 2007
Location: Colombo, Sri Lanka
Posts: 4,376
Eranga has a spectacular aura aboutEranga has a spectacular aura about
Send a message via Yahoo to Eranga
For loop definition is wrong. What you really want to do. Give more details about your application.
__________________
Use an appropriate Subject. "Help, urgent!" isn't one.
To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.

Has someone helped you? Then you can
To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
their helpful post.

Want to make your IDE the best?
To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.

To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.

To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
Bookmark Post in Technorati
Reply With Quote
  #3 (permalink)  
Old 05-21-2008, 11:02 AM
Member
 
Join Date: May 2008
Posts: 3
kusumathatavarthi is on a distinguished road
I am just executing the SCJP Qs

here i want to iterate each set and want to print the name of each drink.
Bookmark Post in Technorati
Reply With Quote
  #4 (permalink)  
Old 05-21-2008, 02:34 PM
DonCash's Avatar
Moderator
 
Join Date: Aug 2007
Location: London, UK
Posts: 239
DonCash will become famous soon enoughDonCash will become famous soon enough
I think you may need to change this to:

Code:
for(String m : tree){ }
I haven't tested it though. Let me know what happens.
__________________
Did this post help you? Please
To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
me!

To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
Bookmark Post in Technorati
Reply With Quote
  #5 (permalink)  
Old 05-21-2008, 02:39 PM
Eranga's Avatar
Moderator
 
Join Date: Jul 2007
Location: Colombo, Sri Lanka
Posts: 4,376
Eranga has a spectacular aura aboutEranga has a spectacular aura about
Send a message via Yahoo to Eranga
I don't think so. Again there is incompatible variables found. Isn't it?
__________________
Use an appropriate Subject. "Help, urgent!" isn't one.
To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.

Has someone helped you? Then you can
To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
their helpful post.

Want to make your IDE the best?
To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.

To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.

To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
Bookmark Post in Technorati
Reply With Quote
  #6 (permalink)  
Old 05-21-2008, 02:47 PM
DonCash's Avatar
Moderator
 
Join Date: Aug 2007
Location: London, UK
Posts: 239
DonCash will become famous soon enoughDonCash will become famous soon enough
Quote:
I don't think so. Again there is incompatible variables found. Isn't it?
Like I said I didnt actually test it but your right. After looking at it further this will actually still cause an error.

'Cannot convert from element type Object to main'
__________________
Did this post help you? Please
To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
me!

To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
Bookmark Post in Technorati
Reply With Quote
  #7 (permalink)  
Old 05-21-2008, 02:57 PM
Member
 
Join Date: May 2008
Posts: 3
kusumathatavarthi is on a distinguished road
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
Bookmark Post in Technorati
Reply With Quote
  #8 (permalink)  
Old 05-21-2008, 03:00 PM
DonCash's Avatar
Moderator
 
Join Date: Aug 2007
Location: London, UK
Posts: 239
DonCash will become famous soon enoughDonCash will become famous soon enough
++i is pre increment

and

i++ is post increment.

Take a look at this:

Incremental Java
__________________
Did this post help you? Please
To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
me!

To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
Bookmark Post in Technorati
Reply With Quote
Sponsored Links
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Need help on a strange file access prob squad Advanced Java 0 03-21-2008 12:55 PM
Prob with an exercise jhetfield18 New To Java 4 02-15-2008 08:11 PM
Threading prob.. banie Java Applets 0 02-05-2008 08:30 AM
having prob with Exception eva New To Java 1 01-04-2008 07:44 PM


All times are GMT +3. The time now is 09:45 PM.


VBulletin, Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Content Relevant URLs by vBSEO ©2007, Crawlability, Inc.
Copyright ©2006 - 2007, www.java-forums.org