Sorting the values of a map.

I have been stuck on this problem for a while. I have a TreeMap, which can be changed to a HashMap if needed, with a set of keys as Strings and values which are Integers.
EXAMPLE
String1, 123
String2, 333
String3, 222
String4, 758
I need the values sorted in decending order (9-0).
Thanks in advance for all your help.

I have been stuck on this problem for a while. I have
a TreeMap, which can be changed to a HashMap if
needed, with a set of keys as Strings and values which
are Integers.You must be the first one who changed a TreeMap into a HashMap and then lived to tell about it. -:)
Anyway a TreeMap is always sorted on key, not value. To have your dataset sorted on value you must reload into another TreeMap and invert the key/value pairs in the process. The values then become keys in the new TreeMap which means that the former values must be unique for this to work.
I'm sure there's a simple solution but it's better if you described what you want to accomplish in general terms than to let people struggle with a solution scenario that's probably suboptimal. How do you want to access your objects and why and when do you need them to be sorted.

Similar Messages

  • Sorting the values in Map

    Hi,
    In my application, i want to use Mapping in the case
    Key -Value
    A - 2
    B - 3
    C - 7
    D - 5
    For that I used HashMap. But I want to sort the values and place in map as from Highest order. For that in google it is suggested to refer SortedMap. But this SortedMap is sorting the Key content only not Value content.
    For sorting the Value's what I have to do under Collection?
    Any idea?

    DHURAI wrote:
    I will explain my concept in detail.
    I am having a String array; a[]={qw,q,as,l,kj,q,q,l}
    From this i am mapping
    key value
    qw 1
    q 3
    as 1
    l 2
    kj 1
    using HashMap.
    From this I want to fetch q whose value is greater. How can I do this?
    Hope this explains better.You still haven't said how often you want to do that. What I explained will work, but it might not be what you want if you often change values.

  • Sort the values in Bex query variable screen

    Dear Experts,
    Is it possible to sort the values of a dropdown list for variables on BEX variable selection screen ? 
    For example, For calender month selection, the values are by default sorted by ascending order.
    Is it possible to sort by descending order ? 
    Regards,
    ravindra

    Hi Ravindra,
    yeah it is possible by writing an abap code for the field calmonth/week...etc this is depends on the F4 help of the selection field. so you need to write a code for F4 help for making it in descending order. hope it helps.
    Thanks,
    Vachan

  • Sorting the values in the HashMap maintaing the key-value relationship

    Hi,
    I want to sort the HashMap based on the values. I have tried several other ways but the closest I can get is sort the values but have to loose the keys. I wanted to sort the collection based on the values but at the same time maintain the key-value relationship. Is there any way I can get this functionality either by using any collection API or by some other way?
    Thanks and appreciate your help....
    --coolers                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                   

    I believe that Commons Collections from Jakarta has something like that.
    http://jakarta.apache.org/commons/collections/
    But I'm not sure.

  • Mapping the values of a Map as Transformation

    Hi,
    Is it possible to map the value of a (Java) Map with a transformation? The values in my Map are arbitrary object hierarchies, and I want to transform them to XML using XStream before they're put to a CLOB field in the database, and vice versa.
    Thanks!

    And I'm using 10g Release 3 (10.1.3)

  • Sorting the values in a column in a Web Template Report

    Hi All,
    I have a report build on WAD in which a table is displayed with certain rows and columns and have certain text values in one column and few numeral values in the other few columns. When i right click on the 1st column(having text values) and click on Sort Ascending by Name, the values are sorted in groups.There are other 3 columns next to that column which have text values as well but when i right click on them and try to sort it in some order(ascending by name/descending by name), there are no reorganization of the values in the column. Again, once i go to the other remaining columns having numeral values in it, the values get sorted in ascending/descending order as per the sort selection. Please advise on how i can make the sort possible in the columns in which the rearrangement is not happening. Do i need to change the Query to some settings? Please advise.
    Thanks!
    Subhra Ghosh.

    Subhra,
    In BW reports, the sorting of characteristic values always happens left-to-right. When you choose to sort by columns 2 - 4, you are actually just specifying whether to sort ascending|descending and/or by key or text. This sort happens for each value of the first column, however. Therefore, the sort in column 2 is only noticeable when you have more than one row with the same value in column 1, etc.
    This sorting behavior is different than the Excel type of sorting, which may be your confusion here.
    If you want to sort first by a column other than column 1, you must swap the columns so that the desired characteristic is in column 1.
    Hope this helps...
    Bob

  • How To sort the values of a OVS result table?

    Hello,
    I'm trying (because i'm new je je), to implement an OVS for an inputfield in my WD app. Now i know for sure that my sophisticated value help do the search of the object and stuff, but i'm wondering if i can "sort" or include the sort method in my result table that is show in my OVS rendered view? Plis if you guys could give me some tutorials or info that would be great
    Kisses
    MC

    ok that's another idea that i had in mind, built a new window, but my issue was how call that window fron the table cell, just like an OVS? wich UI Element help me with that, no link to action, no button, it most be something like an inputfield, how did you do that?
    Kisses
    MC

  • Sorting the Values in Dropdown box values in dashboard

    Hi,
    I have a small problem.   In the dash board I have a drop down which will displays the list of the employess.  How to assign the sort to this.  I have checked all the option but in the web application designed I didnt find any option for it.
    Please help me in this.
    Thanks
    naveen

    Yes, you can do this by specifying this parameter in your web item.
    <param name="ONLY_VALUES" value="X"/>
    This will return all the objects as part of a form so you need to write your own html form around this.
    To sort this within javascript, the easiest thing to do is convert this list of form values to an array, sort this array, and then re-render the form values. There's an example online of doing this with a table here:
    http://javascript.internet.com/forms/sort-data-table.html
    You could do this with for a form in a similar manner.

  • Sort the Valuenode records in table

    Hi Experts,
    Following is the code I wore to retrive and display Portal roles in a table. The context maintained is as follows and got the results properly. I want to know how to sort the table values by Role_Name?. Could some one help me?
    [Value node]      Role_table
    [Value Attribute] RoleID
    [Value Attribute] Role_Name
    [Value Attribute] PCD_Location
    //Retrive the roles from the Role factory          
    String[] theroles = rolefact.getRolesOfUser(unique_id,true);
    for(int i=0; i<theroles.length; i++ )
    //Retrive user attributes and add to the context attribute values     
    String roleid = rolefact.getRole(theroles<i>).getDisplayName();          
    String rolename = rolefact.getRole(theroles<i>).getDescription();
    String role_desc = rolefact.getRole(theroles<i>).getUniqueName();
    IPrivateUserView.IRole_tableElement rowelement = wdContext.createRole_tableElement();
    rowelement.setAttributeValue("RoleID",roleid);
    rowelement.setAttributeValue("Role_Name",rolename);
    rowelement.setAttributeValue("PCD_Location",role_desc);
    //Append the roles obtained and bind to the rolenode
    al.add(rowelement);
    wdContext.nodeRole_table().bind(al);
    Please help me with some code on how to sort the value node table?. I promise to award the points for the right solution. I appreciate coding help.
    Thank you
    Regards
    Maruti

    Hi Maruti,
    1. Get the size of the node, save it in a variable say <b>si</b>
    int si = wdContext.nodeRole_table().size();
    2. Iterate as follows
    for(int i=0;i<si;i++)   
         for(int j=i+1;j<si;j++)
             if(wdContext.nodeRole_table().getRole_tableElementAt(i).getAttributeAsText("Role_Name").compareToIgnoreCase(wdContext.nodeRole_table().getRole_tableElementAt(j).getAttributeAsText("Role_Name"))<0)
             wdContext.nodeRole_table().swapElements(i,j);
    Regards,
    Mathan MP

  • Sort F4 values in BEX variable screen

    Hi ,
    Does anyone know how to sort F4 value help in BEX variable selection screen. This query has come up time and again in SDn and there seems to be no proper reply to this. If anyone has worked on this do let me know.
    Thanks,
    Vaishnavi

    Hi Nara,
    Kindly have a look at below thread,
    Sort the values in Bex query variable screen
    Hope this helps.
    Regards,
    Mani

  • Sorting the numbers in a Varchar2 Column

    I've a column in a table which contains two type of values, either 0-30 or A-Z. Can I sort the values of this column firstly on numbers and then on Characters like this:
    1
    2
    3
    4
    10
    A
    B

    with t as (
               select 'A' str from dual union all
               select 'B' str from dual union all
               select to_char(level) str from dual connect by level <= 10
    select  str
      from  t
      order by case
                 when translate(str,'A0123456789','A') is null then to_number(str)
               end nulls last,
               str
    STR
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    A
    STR
    B
    12 rows selected.
    SQL> SY.

  • Sorting the raws of JTree

    How do i sort the raws which are there in one JTree. But here we have added JTree in JTable. And i want to sort the values of JTree depending on the click of the column of the JTable.

    There is already a topic on this subject
    http://forum.java.sun.com/thread.jsp?forum=57&thread=563889&tstart=45&trange=15
    Denis Krukovsky
    http://dotuseful.sourceforge.net/

  • Sort the Key Figure and put a count on it

    Hi Experts,
    I have a  situation where I have to sort the value of the Key Figures in ascending order and put a count on them.
    Kindly elaborate me a little on this.
    Thanks in advance,
    Kannan

    Hi Kannan,
        If you want to do this setting at the Query Designer level, then select the Properties section for the
    desired Key figure say K1.then select the "Calculations " tab.  Under the Local calculations for "Calculate Results as" select "Counter for all detailed values".Save the query.
    Open the query (say) at Bex Analyzer. From  the context menu for the key figure K1, select "Properties"-->then under Sorting tab select the required order.
    The options mentioned above, i.e  "calculations" and "Sort" is available on web too in the context menu for the key figure.
    The above mentioned setting wil be a display setting>You can modify it as per your requirement at Query Designer.
    NOTE:
    If your requirement is such that K1, should always display the counter , then while creation of the K1 itself , you can select the Exception Aggregation of Type "Counter(all values)". Then, the setting will be permanent.(design time)
    Hope the information helps!
    Best Regards,
    Akshata
    Edited by: Akshata Shenoy on Jun 2, 2009 12:25 PM
    Edited by: Akshata Shenoy on Jun 2, 2009 12:27 PM

  • Sort the Shortcut Dropdownlist of Team Member Home Page in Oracle Project

    In Team Member Home Page, need to sort the values in the Shortcuts dropdown list.
    I have checked the VO(ShortcutDroplistVO), which is used as Dummy VO.
    Checked the ShortcutDroplistAM,ShortcutDroplistRN,ShortCutDroplistCO, which is attached to the Shortcut field.
    Shortcut Dropdown list values are not given in Controller class,View Object.
    I am confused how the values are populated dynamically?
    Could anyone help me to solve this issue?

    There are two ways to go ahead:
    First one:
    1. Extend controller and in processRequest get ShortcutDropListVO object
    2.get the query using vo.getQuery()
    3. Add orderby caluse to the query and set it using vo.setQuery()
    But vo.setQuery() may or may not work properly.
    Second one:
    1. Create custom VO(as required) in Jdeveloper under custom folder structure and move it into server
    2. extend controller and in processRequest attach custom VO to seeded AM (you can get sample code in many threads)
    3. get drop down bean value and attach custom VO to it using sample code
    OAMessageChoiceBean bean = (OAMessageChoiceBean)webBean.findChildRecursive("beanID");
    bean.setPickListViewObjectDefinitionName();
    bean.setPickListCacheEnabled(false);
    Note: custom VO should have same columns and order of columns as seeded VO
    -Anand
    Edited by: T.A.Anand on 25 Nov, 2010 7:55 PM

  • Sort the payload before mapping to target

    Hi
    My Source structure is a sbelow
    <ROW>
    <ordernumber>01<ordernumber>
    <EAN>E1<EAN>
    <ROW>
    <ROW>
    <ordernumber>01<ordernumber>
    <EAN>E2<EAN>
    <ROW>
    <ROW>
    <ordernumber>01<ordernumber>
    <EAN>E3<EAN>
    <ROW>
    <ROW>
    <ordernumber>01<ordernumber>
    <EAN>E1<EAN>
    <ROW>
    My Target is as below
    <Header>
    <Ordernumber>01<ordernumber>
    <item>
            <EAN>E1<EAN>
    <item>
    <item>
            <EAN>E2<EAN>
    <item>
    <item>
            <EAN>E3<EAN>
    <item>
    <Header>
    My question how can i sort the EAN numbers in the source structures and map to the target.
    Thanks
    Srinivas

    I tested it if your source and target structure matches as I have given here then it will definitely work. try it out.
    Source Structure
    <?xml version="1.0" encoding="UTF-8"?>
    <ns0:MT_Test_forum xmlns:ns0="http://yash.com/yh1309/EDIFile_2_EDIFile">
       <Row>
          <OrderNo>1</OrderNo>
          <EAN>A</EAN>
       </Row>
       <Row>
          <OrderNo>2</OrderNo>
          <EAN>A</EAN>
       </Row>
       <Row>
          <OrderNo>1</OrderNo>
          <EAN>B</EAN>
       </Row>
       <Row>
          <OrderNo>2</OrderNo>
          <EAN>B</EAN>
       </Row>
       <Row>
          <OrderNo>1</OrderNo>
          <EAN>C</EAN>
       </Row>
       <Row>
          <OrderNo>3</OrderNo>
          <EAN>A</EAN>
       </Row>
    </ns0:MT_Test_forum>
    Target Structure
    <?xml version="1.0" encoding="UTF-8"?>
    <ns0:MT_Test_forum_tar xmlns:ns0="http://yash.com/yh1309/EDIFile_2_EDIFile">
       <Header>
          <OrderNo>
             <orderno>1</orderno>
             <Item>
                <EAN>A</EAN>
             </Item>
             <Item>
                <EAN>B</EAN>
             </Item>
             <Item>
                <EAN>C</EAN>
             </Item>
          </OrderNo>
          <OrderNo>
             <orderno>2</orderno>
             <Item>
                <EAN>A</EAN>
             </Item>
             <Item>
                <EAN>B</EAN>
             </Item>
          </OrderNo>
          <OrderNo>
             <orderno>3</orderno>
             <Item>
                <EAN>A</EAN>
             </Item>
          </OrderNo>
       </Header>
    </ns0:MT_Test_forum_tar>
    OrderNor -> RemoveContext -> Sort -> SplitByValue( Valuechange) ->collapseContext--> OrderNo
    OrderNo -> RemoveContext -> Sort -> SplitByValue( Valuechange) ->Item
    OrderNor -> RemoveContext -> Sort -> SplitByValue( Valuechange) ->collapseContext--> splitByValue(each value)--->orderno
    OrderNo-> RemoveContext - > SortByKey -->SplitByValue(Each Value) -> EAN
    EAN -> RemoveContext -> /
    notice that a field name orderno inside each occurence of <OrderNo> in the target structure to get the order number in that field

Maybe you are looking for

  • QuickTime Error Code

    When I deleted QuickTime the first time off my computer I had to install QuickTime 7.0 for my New IPod Nano. Well long story short When I run QuickTime it is saying that ( I have an error:-2093.) Does anybody have a clue what that is? As well as when

  • WS7+PHPPack: LDAP Extension support

    We're trying to install the PHP Pack on WS7, however we have a couple apps that require the LDAP extension. The PHP Pack does not include the LDAP Extension. We tried compiling from source and including the LDAP extension, however, eventually it beca

  • Applets and text...

    I need a way to display text in an applet without needing coordinates. What I need to do is display a word with a number in front of it then a single space after and the same again only the number increases by 1. I have to use a looping structure for

  • Online Data Archival

    Hi, In my new project, I need to work on online data archival where application can access the archived database online. Can yuo please help me with any link where I can find information/steps for same. Thanks

  • Unable to open some websites since I moved to BT

    Hi I am new on here, so please move if I have posted in the wrong place. Since I moved to BT (Home Hub 4, normal broadband) I am having trouble on all my devices connecting to certain websites. On my laptop I just get the Oops, Internet Explorer coul