473,385 Members | 1,752 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

TreeSet is not sorting -- help required to find why

using Treeset to sort numbers .But sorting is not happening properly.Below is the code

IDataCursor pipelineCursor = pipeline.getCursor();
String keyName = IDataUtil.getString( pipelineCursor, "keyName" );
java.util.TreeSet set = null;
IData[] list = IDataUtil.getIDataArray( pipelineCursor, "list" );
if ( list != null)
{
for ( int i = 0; i < list.length; i++ )
{
IDataCursor tempCursor = list[i].getCursor();
if(tempCursor.next(keyName))
{
if(set == null)
set = new java.util.TreeSet();
set.add((String)tempCursor.getValue());
}
}
if(set!=null)
{
IDataUtil.put(pipelineCursor,"set",set);
IDataUtil.put( pipelineCursor, "min", (String)set.first() );
IDataUtil.put( pipelineCursor, "max", (String)set.last() );
}
}




pipelineCursor.destroy();

input :1,100,2,300,1000,5

out put came

min 1
max 5


If the number list is above 1000 then its returning

min as '1' but max always 999

help me to find the problem
Apr 20 '10 #1
1 2912
jkmyoung
2,057 Expert 2GB
You're inserting the numbers as strings:
set.add((String)tempCursor.getValue());

but expecting them to be sorted as Integers.
Add them as Integers.
Apr 20 '10 #2

Sign in to post your reply or Sign up for a free account.

Similar topics

12
by: pmud | last post by:
Hi, I am using teh following code for sorting the data grid but it doesnt work. I have set the auto generate columns to false. & set the sort expression for each field as the anme of that...
40
by: Elijah Bailey | last post by:
I want to sort a set of records using STL's sort() function, but dont see an easy way to do it. I have a char *data; which has size mn bytes where m is size of the record and n is the...
22
by: mike | last post by:
If I had a date in the format "01-Jan-05" it does not sort properly with my sort routine: function compareDate(a,b) { var date_a = new Date(a); var date_b = new Date(b); if (date_a < date_b)...
1
by: a | last post by:
I have the following problem, where the Song is a class created by me. The first add is ok. The second caused this error. Exception in thread "main" java.lang.ClassCastException: library.Song...
1
by: Jeremy | last post by:
I want my gird to sort only the items on the current page when I click on a column header. I wrote a little test app, but when I sort it pulls in items from other pages and places them on the current...
4
by: Mark Travis | last post by:
Hi all, I have written a simple Web Application that displays a query result onto a page using the ASP DataGrid. To Digress ======= Development information about the page is as follows 1....
0
by: Brian Henry | last post by:
Here is another virtual mode example for the .NET 2.0 framework while working with the list view. Since you can not access the items collection of the list view you need to do sorting another...
0
by: rupalirane07 | last post by:
Both grids displays fine. But the problem is only parent datagrid sorting works fine but when i clik on child datagrid for sorting it gives me error: NullReferenceException error Any...
1
KevinADC
by: KevinADC | last post by:
Introduction In part one we discussed the default sort function. In part two we will discuss more advanced techniques you can use to sort data. Some of the techniques might introduce unfamiliar...
1
by: nvinhphu | last post by:
Hello everybody, Is there any STL-based data structure that is equivalent to Java::TreeSet? Thank you very much. Phu
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
marktang
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,...
0
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 using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.