Sort arrayList for integer

hi,
some doubts on the syntax
rows.add(String.valueOf(destList));is this the correct syntax eventhough my "destList" is an integer?
Collections.sort(rows);i would like to sort my arrayList but it doesnt seem to work with this syntax.the values in my arraylist are in integer.
please help.thanks

Maybe a little off topic, but this might be of interest to anyone that wants to sort a 2 dim object array (Object[][]).
As part of the formatteddataset open source API I have a utility class called ArraySQL. It allows you to issue a reduced sql syntax against an array (i.e. specify a column list, where and order by clauses). The basic idea is that because a 2 dim Array is conceptually similar to a db table you could be able to query it. I will be releasing on sourceforge in a couple weeks, but in the meantime if anyone is interested i can send it to them. Here are some examples
import com.fdsapi.arrays.ArraySQL;
Object[][] data{
      {"jim","smith", new Integer(200)}, 
      {"jeff","souza", new Integer(500)},
      {"jim","anderson", new Integer(100)},
      {"stan","jones",new Integer(2000)}};
ArraySQL asql=new ArraySQL("select * from array where col0 in ('jim', 'jeff') order by col0 asc, col1 desc")
Object[][] newData=asql.execute(data);
asql=new ("select * from array order by col2 desc");
newData=asql.execute(data);steve -
http://www.fdsapi.com - An easy, fast, extensible way of generating xml and html
http://www.jamonapi.com - An easy way to monitor application code.
Both tools are open source and available for download on the given sites.

Similar Messages

  • ADF FACES: how to preserve the sort criteria for an af:table

    How can I preserve the sort criteria on an af:table across page invocations? I've searched all through the forum and I don't see anything on this topic.
    I simply want the sort criteria (from when the user clicks on a column header) to be remembered across multiple uses of the page. I know that the control handles this itself for multiple invocations of the same page (like when you page through the table). But I need to preserve the sort order so I can install it again when someone leaves the page and then returns to it.
    I've tried various attempts using a SortListener to record the sort criteria, but I can't figure out how to reinstall the criteria without generating exceptions from the table control.
    Any pointers on how to do this would be greatly appreciated.
    Thanks.
    Larry.

    Ok, I've solved the problems with the odd behavior by always creating a new model when the table data changes and copying the sort criteria into the new model, like this:
            // Construct our own CollectionModel from this result set
            if(_model == null) {
                // Construct the initial data model and set the starting sort criteria
                ListDataModel m = new ListDataModel(results);
                _model = new SortableModel(m);
                // Set the sort criteria to last name
                ArrayList criteria = new ArrayList();
                criteria.add(new SortCriterion("lastName", true));
                _model.setSortCriteria(criteria);
            } else {
                // Construct a new model so the table "sees" the change
                ListDataModel m = new ListDataModel(results);
                SortableModel sm = new SortableModel(m);
                sm.setSortCriteria(_model.getSortCriteria());
                _model = sm;
            }But, I end up with one final thing that doesn't work. In the "then" clause above, I try to set the initial sort criteria for the table - it has no effect. When the table is rendered, it is not sorted in any way.
    How can I specify an initial sort order for the table? Why is it ignoring the sort criteria on the model?
    Thanks.

  • Collecstions.sort(ArrayList) - Please Explain

    Hello,
    This is a rewrite of an earlier question. Hopefully, I better formed the question in this post.
    Can anyone explain why the first code example requires that I write a compareTo() method (called by Collections.sort(bidList)) and a toString() method (called by System.out.println(bidList), while the second code example requires no such additional code in my program?
    Thanks for all responses.
    Karl
    First Code Example (Requires comparTo() and toString() methods in the program.)
         public static void main(String[] args) {
            // fill a list with 5 bids
            ArrayList bidList = new ArrayList();
            for(int i=0; i<5; i++){
                //generate random number 0-100 for a bid amount
                bidList.add(new AuctionBid("Bidder" + i, (int)(Math.random()*100)));
            //sort the bids in natural order and display them
            Collections.sort(bidList); //Why does this call method compareTo()
            System.out.println("Natural order sort by bid amount");
            System.out.println(bidList); //Why does this call method toString()
    }Second Code Example (Does not require compareTo() or toString() methods in the program.)
            public static void main(String[] args) {
            // fill a list with 5 bids
            System.out.println("Printing bidList from Array: ");
            String[] bidList = new String[5]; 
            for(int i=0; i<5; i++){
                if(i==0){bidList[i] = "Zoey";}
                else if (i==1){bidList[i] = "Megan";}
                 else if (i==2){bidList[i] = "Larrry";}
                  else if (i==3){bidList[i] = "Brian";}
                   else if (i==4){bidList[i] = "Abigail";}
       List list2 = Arrays.asList(bidList); // Does NOT requre a toString() method to be coded.
       System.out.println("Printing Unsorted list2: ");
       System.out.println(list2);
       Collections.sort(list2); // Does NOT require a compareTo() method to be coded.
       System.out.println("Printing Sorted list2: ");
       System.out.println(list2);
    }

    To answer your first question, Collections doesn't
    know how to sort any ArrayList unless the objects
    implement the Comparable interface and define the
    compareTo method. The String class already defines
    the compareTo method for you, and that's why your
    second ArrayList doesn't require you to write one.
    In your first list you're loading AuctionBid
    references, and Collections can't sort that list
    unless your AuctionBid class implements Comparable
    and defines the compareTo method.
    To answer your second question, System.out.println
    calls toString on the object reference you pass to
    it, unless the reference actually IS a String
    reference. How else could it get a string
    representation of an object without calling toString
    on it?Thank you!
    That makes sense.
    Karl

  • Sorting ArrayList multiple times on Multiple Criteria

    I have an arraylist that is sorted with Collection.sort() calling the ComparTo() included below. CompareTo sorts the file on totalLaps, totalSeconds, and etc.. The question is how do I change the sort criteria later in my process so that the arraylist is sorted on sequence number (the first field and a long number)? The only way I can currently think of doing it is to copy the array and create a separate class file like RaceDetail2 that implements a different CompareTo. To me that seems ridiculous!
    I've self tought myself Java using the online tutorials and a few books so sometimes I find I have some basic gaps in knowledge about the language. What am I missing? Seems like it should be simple.
    private ArrayList detailsArrayList = new ArrayList( );
    // Sort arraylist using compareTo method in RaceDetail file
    Collections.sort(detailsArrayList);
    public class RaceDetail implements Comparable, Cloneable {
         public RaceDetail( long seqNum, String boatNumText, int lapNum, String penalty, String question, long seconds, int totalLaps, long totalSecs, long lastSeqNum, long avg, long interval )
    public int compareTo( Object o )
         RaceDetail rd = (RaceDetail) o;
         int lastCmp = (totalLaps < rd.totalLaps ? -1: (totalLaps == rd.totalLaps ? 0: 1));
         int lastCmpA = boatNumText.compareTo(rd.boatNumText);
         int lastCmpB = (lapNum < rd.lapNum ? -1: (lapNum == rd.lapNum ? 0 : 1 ));
         int lastCmpC = (totalSecs < rd.totalSecs ? -1 : (totalSecs == rd.totalSecs ? 0 : 1 ));
         int lastCmpD = (seqNum < rd.seqNum ? -1 : (seqNum == rd.seqNum ? 0 : 1 ));
         int lastCmpE = (seconds < rd.seconds ? -1 : (seconds == rd.seconds ? 0 : 1 ));
         int lastCmpF = (lastSeqNum < rd.lastSeqNum ? -1 : (lastSeqNum == rd.lastSeqNum ? 0 : 1 ));
         // TotalLaps - Descending, TotalSeconds - ascending, lastSeqNum - ascending
         // Boat - Ascending, Second - ascending, seqNum - ascending
         return (lastCmp !=0 ? -lastCmp :
              (lastCmpC !=0 ? lastCmpC :
                   (lastCmpF !=0 ? lastCmpF :
                        (lastCmpA !=0 ? lastCmpA :
                             (lastCmpE !=0 ? lastCmpE :
                                  lastCmpD)))));
    }

    Thanks talden, adding the comparator below in my main program flow worked and now the arraylist sorts correctly. A couple of additional questions. I tried to place this in my RaceDetail class file and received a compile error so placed it in the main program flow and it worked fine. For organization, I would like to place all my sort routines together. Is there some trick to calling this method if I place it in my RaceDetail? Am I even allowed to do that?
    dhall - just to give you a laugh, this arraylist populates a JTable, uses a TableModel, and the TableSorter from the tutorial. Sorting works great in the JTable. Problem is I have to sort the arraylist a couple of times to calculate some of the fields such as lap times and total laps. I went through the TableSorter 5 or 6 times and never could figure out how to adapt it for what I wanted to do. So here I am using an example in my program and can't interpret it.
    Collections.sort( detailsArrayListLeft, SORT_BY_SEQUENCE );
    static final Comparator SORT_BY_SEQUENCE = new Comparator() {
    public int compare ( Object o1, Object o2 )
         RaceDetail rd1 = (RaceDetail) o1;
         RaceDetail rd2 = (RaceDetail) o2;
         return (rd1.seqNum() < rd2.seqNum() ? -1 : (rd1.seqNum() == rd2.seqNum() ? 0 : 1 ));

  • How can i change sort options for a playlist in ios8? I would like to sort by album, or album artist like I can in iTunes for OSX.

    So here's an example of why I would like to figure this out. I have a playlist on my iPhone that contains only new music. I would like to be able to sort this playlist by artist, so that when i click on the playlist, I can quickly find the album I have added to the playlist and play it. Currently, I can only see a long list of tracks. How do you sort playlists?
    Thanks!

    I just found the solution to this myself.
    In a very un-Apple way, this is an undocumented feature only accessible by right- (or control-) clicking.
    1. Change one track to your desired sort settings (for instance, set the Sort Artist to Yankovic, Weird Al.
    2. Right-click on that track. In the contextual menu that appears, there is a new submenu called "Apply Sort Field." If you choose "Same Artist," it will apply your new sorting information to all your other tracks by "Weird Al" Yankovic (or, if you are not a huge nerd, any other artist you substitute).

  • Providing sorting filters for a table in webdynpro java application

    ho to provide sorting  , filters , for a table in webdynpro java application .

    Hi Pradeep,
    Please go through the following article on implementation of filtering and sorting:
    https://www.sdn.sap.com/irj/scn/go/portal/prtroot/docs/library/uuid/f024364b-3086-2b10-b2be-c0ed7d33fe65
    The article contains a link to a sample application using the TableSorter and TableFilter Class.
    The same classes can be used by any other web dynpro application. Download the sample application and copy the classes. In case of a specific requirement, modify the TableSorter and TableFilter classes.
    Regards,
    Kartikaye

  • Can't change sort settings for multiple items in iTunes 7.1

    iTunes 7.1 introduces a great feature—the ability to set a separate Sort Name, Sort Artist, Sort Album, etc. This means that "Weird Al" Yankovic songs can finally appear down among the Y's instead of up at the top of every list, by changing the Sort Artist to Yankovic, Weird Al.
    Unfortunately, this feature is fatally crippled in 7.1. As far as I can tell, you can only change the Sorting information on individual tracks. When you change the information for multiple tracks, the Sorting tab doesn't show up. This renders the feature all but useless.
    Let's say (hypothetically) that your friend is an enormous nerd (in theory) and your friend has 139 "Weird Al" Yankovic tracks (for the purposes of this example only, of course). Instead of just selecting all these tracks at once and changing the Sort Artist to Yankovic, "Weird Al", I (I mean, he) has to retype this information for each individual track. That's crazy! Surely this must be a bug.
    Core 2 Duo 20" iMac   Mac OS X (10.4.8)  

    I just found the solution to this myself.
    In a very un-Apple way, this is an undocumented feature only accessible by right- (or control-) clicking.
    1. Change one track to your desired sort settings (for instance, set the Sort Artist to Yankovic, Weird Al.
    2. Right-click on that track. In the contextual menu that appears, there is a new submenu called "Apply Sort Field." If you choose "Same Artist," it will apply your new sorting information to all your other tracks by "Weird Al" Yankovic (or, if you are not a huge nerd, any other artist you substitute).

  • How can I get (using API) the current sort column for some report

    hello,
    How can I get (using API) the current sort column for some report ? For example something like "fsp_sort_1_desc" - if the user sorts by the first column ?
    I cannot use the :REQUEST for this, sometimes the current sort column is not in the :REQUEST, but it is still active.
    I thought it was posssible by using
    APEX_UTIL.GET_PREFERENCE (
    p_preference IN VARCHAR2 DEFAULT NULL,
    p_user IN VARCHAR2 DEFAULT V('USER'))
    RETURN VARCHAR2;
    function, but I don't really know which preference should I pass as parameter.
    looking in WWV_FLOW_PREFERENCES$, i saw preferences_names like FSP4000_P527_R6281510839654570_SORT , I'm not sure how this name is formed.
    I'm using generic columns for that complex report (which has a flexible number of columns shown), and the idea is that sometimes I have to overwrite that sort column, in case the user chose the version of the report with fewer columns than the previous one.
    Can I get (using API) a list of all preferences set for some user ?
    Thank you,

    seems that it is FSP<app_number>P<pagenumber>R<regionnumber>_SORT.
    is there anyplace where I can get these kind of things documented ?
    Thank you.

  • Default Sort Order for Library View

    It would be fantastic if there were a user defined preference for a default sort order in Library view. For example, some users may prefer to always view the images by File Name, or Rating, etc, without having to change the sort order for each individual folder they view via Lightroom.
    Thanks!

    Thanks for your suggestion Allan, but it doesn't work.
    I'm specifically referring to the defaults that Aperture 3 adopts when you use the "File, Import, Folders as Projects with the projects and albums setting.
    What I'm finding is regardless of the setting in the Library preferences, the default sort order for the project is Date and Manual for the album.
    Yet if I create a project manually the default sort order is as per the Library prefs. Strange.

  • Looking for a way to change sort order for albums

    I know how to set the sort order for each individual song (Sort tab on song info), but is there a way to set sort order for multiple tracks?

    Please help!

  • How to change sort order for Notes in iOS?

    When using Notes in OS 10.10, I can change the sort order. However, I cannot see how to change the sort order for Notes in iOS8 on my iPhone. I sync using iCloud, but the iPhone does not pick up the sort order (alpha) that I have chosen on my MBP.
    Is it possible to change the sort order on phones?
    Thanks.

    View > Sort By > Title

  • How do I change the Sort order for Music Video's on the iPad

    Hi All,
    Apologies if this has been dealt with elsewhere - I can find posts about sort order for TV Shows and Movies but not Music Video's.
    When I sync my music video's the appear in Track order in the video app and I cannot find how to change the sort order to 'by Artist' (or any other order come to that).
    Any ideas please>

    Hi!
    Im afraid I believe this cannot be done yet. Sorry!
    You can try submitting feedback to apple by clicking [here|http://www.apple.com/feedback/ipad.html] if you wish.
    Hope this helps!

  • Default column sort order for 11g table

    Could anyone give me some indication on how I would go about setting the default sort order for a table?
    I have a table with a few columns, and dataset returns in a particular order, but my table decides to sort if in any given order until I manually click on the column header and sort it.
    I would like to have it done by default on a particular field.
    Any info is appreciated.
    Thanks
    Jonny

    As Chris says, the easiest way and best re-use way is to use the order-by clause in your underlying model layer SQL query. For instance in ADF BC this would be in a View Object's query.
    However as you haven't dictated your model layer technology, there is another way in JDev 11g. In your web page that contains the ADF Faces RC table, select the binding tab at the bottom of the page, then double click on the iterator in the binding page, and in the Edit Iterator Binding dialog, select the Sort Criteria tab. This allows you to override the sort order on the iterator's columns.
    CM.

  • Sort order for Simplified Chinese (pinyin)

    FrameMaker 10 (Windows)
    It seems that if I specify the sort order for Simplified Chinese (pinyin) on the reference page,
    index entries that start with "i" and "v" are not shown under their corresponding group titles.
    (I assume that this may be due to the fact that pinyin words never start with these letters.)
    If I have an entry that starts with an English word like "IP," it appears under the "J" group.
    I want the entry to appear under the "I" group. How can I do this?
    I have the IX reference page set up as follows:
    GroupTitlesIX paragraph
    Symbols[\];Numerics[0];A;B;C;D;E;F;G;H;I;J;K;L;M;N;O;P;Q;R;S;T;U;V;W;X;Y;Z;
    SortOrderIX paragraph
    <$symbols><$numerics><$alphabetics><$pinyin>
    I've also tried:
    SortOrderIX paragraph
    <$symbols><$numerics><$pinyin>
    Thanks in advance.
    Tak Osato

    I sort of found a workaround, but it may lead to other problems, so use it at your own risk.
    It also requires a bit of work.
    The idea is to use the sort order for Japanese by specifying the following in the IX reference page.
    Symbols[\ ];数字[0];A;B;C;D;E;F;G;H;I;J;K;L;M;N;O;P;Q;R;S;T;U;V;W;X;Y;Z;あ;い;う;え;お;か;き;く;け;こ;さ;し;す;せ;そ ;た;ち;つ;て;と;な;に;ぬ;ね;の;は;ひ;ふ;へ;ほ;ま;み;む;め;も;や;ゆ;よ;ら;り;る;れ;ろ;わ;ん;[ ]
    <$symbols><$numerics><$alphabetics><$kana>
    Then, you need to capitalize the first letter in the bracket used for sorting for every index entry.
    Example:
    Instead of
    画面[hua4mian4]
    specify
    画面[Hua4mian4]
    Now, I'm wondering if there is a way to do a search and replace on all index entries to capitalize the first letter...

  • Sort Order for Legend and X Axis

    Does anyone know of a way to keep a specific sort order for both the X Axis and the Legend. Both start with numbers and I can get one or the other to sort correcly on the chart but not both. Biggest problem is not all of the legend items are in the first X Axis item so the colors change on the bar graph depending on the legend items in the first X Axis item.

    If you tie bar colors with values, how you will differentiate the bars for different legends.
    Take an example, there are three columns Employee, Location and salery have following values
    Employee Location Salery
    A London 30000
    B Chicago 40000
    C London 50000
    D Chicago 60000
    if we keep Location as Legend and Employee in X Axis, and sort Legend first then Employee. Set Blue for Chicago and Red for London, First two blue bars for A and C will be displayed and then two red bars for B and D will be displayed. Order in X axis will be A,C,B and D. This is not in sequence but this is the way it will and it should work. If you sort by Employee instead if Location, you will get sequence in X axis, but the same colored bars wont be together.
    Thanks
    Swami

Maybe you are looking for

  • Lock screen when watching video's

    Has anyone found a way to lock the touch screen when watching a video or playing music in the iPhone? When watching a video on my iPod I can use the lock button on the top to prevent the touch wheel to register misc bumps.

  • I updated to 7.1 and now when I plug my phone into the computer, it says there are no pictures??????

    I updated to 7.1 and now when I plug my phone into the computer, it says there are no pictures??????  When I have 500 pictures on it!!!!!  Im soooooo mad I did the update! Worst decision ever!!!!!!!!!!   I am SOOOO ready to leave the IPHONE alone- ma

  • Mouse Over Value in Pie Chart

    I have two questions - 1. How do i restrict the no. of decimals in the Mouse Over values for Percentage in a Pie Chart ? The numeric values i can control but the percentage (which the system calculates) seems to be set at default two decimal places.

  • VIDEO PLAYBACK ANOMALY N95

    I'm using the N95 with the TV-OUT cables connected to an external monitor. While watching a Video, if an incoming call is answered, the video playback is paused for the duration of the call. When resuming playback of the video after hanging-up the ca

  • Contextual menu items remain after Bitcasa removal - why?

    Hello there. I'm looking for a solution of Bitcasa context menu items that won't go away. After removing the app they still appear in the Finder context menus. I already searched the usual places like Keyboard Shortcuts, Services, etc. but couldn't f