Results 1 to 3 of 3
Thread: Casting an int from a sorted set
- 03-17-2010, 01:54 PM #1
Member
- Join Date
- Mar 2010
- Posts
- 2
- Rep Power
- 0
Casting an int from a sorted set
Hi,
trying to write a method that will return an int from a sorted set. I get a messasge "Semantic error: java.lang.String cannot be cast to java.lang.Integer". Is there any way in which I can return an int?
[code]
public int getLowestValueInSet()
{
TreeSet tSet = new TreeSet();
tSet.add("7")
tSet.add("3");
tSet.add("4");
// System.out.println("Lowest value in Java TreeSet is : " + tSet.first());
int lowestValue=(Integer)tSet.first();
return lowestValue;
}
[code]
- 03-17-2010, 02:44 PM #2
Senior Member
- Join Date
- Dec 2009
- Location
- Belgrade, Serbia
- Posts
- 364
- Rep Power
- 4
Maybe this:
TreeSet<Integer> tSet = new TreeSet<Integer>();
tSet.add(new Integer(7));
tSet.add(new Integer(4));
tSet.add(new Integer(3));
- 03-17-2010, 07:09 PM #3
Member
- Join Date
- Mar 2010
- Posts
- 2
- Rep Power
- 0
Thanks, that worked a treat. I applied your solution to the method that created the set I was using and it all worked. Thanks for taking the time to reply.
F.Y.I.
Java Code:public SortedSet makeCalendar(int [] suppliedDays) { SortedSet<Integer> calendar = new TreeSet<Integer>(); for (Integer aDay : suppliedDays) { calendar.add(new Integer(aDay)); } return calendar; } }
Similar Threads
-
Sorted LinkList problem
By koolaqua16 in forum Advanced JavaReplies: 1Last Post: 08-08-2009, 06:49 AM -
how to right a program that find kth number in two sorted array?
By fireball2008 in forum New To JavaReplies: 8Last Post: 04-22-2008, 03:21 AM -
How to create a Sorted List in Java
By Java Tip in forum java.langReplies: 0Last Post: 04-16-2008, 10:31 PM -
Sorting, Searching, and Inserting into a sorted array
By Java Tip in forum java.langReplies: 0Last Post: 04-14-2008, 08:39 PM -
My doublyLinked list does not get sorted
By hasani6leap in forum New To JavaReplies: 0Last Post: 01-06-2008, 03:09 PM


LinkBack URL
About LinkBacks
Reply With Quote

Bookmarks