How to disable sorting in hash map

im adding like this ,
Map Params = new HashMap();
params.put("orderYear", "1");
params.put("distrChannel", "2");
params.put("salesOffice", "3");
while iterating answer is coming like this
1
3
2
but i want
1
2
3
thanks in advance
gowri

while iterating answer is coming like this
1
3
2You can print the Sorted HashMap values using the following way:
          HashMap map = new HashMap();
          map.put("1","First");
          map.put("2","Second");
          map.put("3","Third");
          ArrayList keys = new ArrayList();
          keys.addAll(map.keySet());
          Collections.sort(keys);
          Iterator it = keys.iterator();
          while (it.hasNext())
          System.out.println(it.next());
Refer the outcome keys, and print the HashMap values, thats all.

Similar Messages

  • How to disable sorting for some columns in a ALV GRID?

    Hi i have requirement where I have to disable sorting for some columns in a ALV GRID. i am using REUSE_ALV_GRID_DISPLAY function module.
    Can anybody help me. how to acieve this? Any code snippets will really be appreciated.

    Hi,
    I have tried this but not completely successful. I think this can be done using the OOPS method.
      DATA: it_event_exit TYPE  slis_t_event_exit.
      DATA: w_exit TYPE slis_event_exit.
      w_exit-ucomm = '&ODN'.
      w_exit-before = 'X'.
      CLEAR w_exit-after.
      APPEND w_exit TO it_event_exit.
      w_exit-ucomm = '&OUP'.
      w_exit-before = 'X'.
      CLEAR w_exit-after.
      APPEND w_exit TO it_event_exit.
      CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY'
        EXPORTING
          i_callback_program          = w_repid
          i_callback_top_of_page      = 'ALV_TOP_OF_PAGE'
          i_callback_html_top_of_page = 'ALV_HTML_TOP_OF_PAGE'
          i_callback_user_command     = 'USER_COMMAND'  <- User command form
          is_layout                   = wm_layout
          it_fieldcat                 = wt_fieldcat
          it_events                   = i_events
          it_event_exit               = it_event_exit    <- Need to fill
          it_sort                     = wt_sort
          i_default                   = 'X'
    Now you can capture this events in the user command
    FORM user_command  USING r_ucomm LIKE sy-ucomm
                             rs_selfield TYPE slis_selfield.
      IF r_ucomm = '&OUP' and rs_selfield-SEL_TAB_FIELD = 'Your field name'.
      ENDIF.
    ENDFORM.                    "user_command
    In this form you will get the function code in 'r_ucomm' and the field selected for sorting in 'rs_selfield-SEL_TAB_FIELD'. But reseting 'r_ucomm' will not work.
    May be somebody else can give some help on this.
    But this will work if you follow the oop method.
    Please see this document for more info.
    http://www.sdn.sap.com/irj/servlet/prt/portal/prtroot/com.sap.km.cm.docs/library/webas/abap/an easy reference for alv grid control.pdf
    Thanks
    Vinod

  • Sorting a hash map

    I have a hashmap with strings as keys, and float values as values, like below:
    {"anne=0.23453, barry=1.254339,steven=0.12449... }
    what i want to do is sort this hashmap according to the float values, returning the highest float value first. What i am currently doing is, swapping the keys with the values, so that the floats are the keys, and sorting them with a hashmap:
                     Set set = map1.keySet(); 
                     Map invertedMap = new HashMap();
                     for(Object o : set)
                         float val = (Float)map1.get(o);
                         invertedMap.put(val, o);
                TreeMap sorted = new TreeMap(Collections.reverseOrder());
                sorted.putAll(map1);
                Set set1 = sorted.keySet();
                  Iterator it = set1.iterator();
                        while(it.hasNext()) {
                            Object o = it.next();
                            System.out.println( o + " " + map1.get(o));
            }The problem here is that in the hash tables there a few floats are the same value, ie henry=1.6743, and mary=1.6743
    so when i invert the hash table, making 1.6743 one of these is ignored. Can anbody think of a way i can do this?
    Id appreciate any help
    Thanks

    Thanks, ive stored the entrySet in a list. A little
    unsure how to go about writting comparator to sort
    them by value though. Would you be able to explain
    this in a little more detail, please?Write a class that implements java.util.Comparator. Thre's but one method to implement, that is
    public int compare(Object o1, Object o2);
    Expect the arguments to be keys in your map. Fetch the value for each key and compare the values. That should be a problem since, if I got it right, those are java.lang.Floats, which implement java.lang.Comparable, so you can simply return: value1.compareTo(value2).
    Take a minute or two to read the Javadoc of the Comparator's compare method.

  • How to disable sorting in ListView component?

    Hi ,
    I am using a listview component and is there any option to disable the sorting option.
    Regards,
    Nagaraj

    Use fixed header size, that will stop resizing the column width at run time.
    Regards,
    Anjani Kumar C.A.

  • How to make sorting in hash table efficient

    Hi guys,
    I am relatively new to collections.
    I have a HashTable which has 100000 records in it, when I sort it, it takes a lot of time to get it done.
    As the Hashtable methods are synchronised so even I can't use threads to perform this quickely for me.
    Can any one provide any solution using multi threading or any other method to achieve the optimization in
    sorting the hashtable.
    Thanks,
    Atul

    As already suggested, use TreeMap if you want to build your table in sorted key order. Otherwise, if you want to sort after the fact, you could do one of the following:
    SortedSet sortedKeys = new TreeSet(map.keySet());
    // or
    List sortedKeys = new TreeSet(map.keySet());
    Collections.sort(sortedKeys);Note that this will NOT affect that order in the map. It only affects the order of the extracted keys.
    Also not that if sorting 100,000 items is taking "a long time," then you probably wrote your own sort algorithm and it's probably O(n^2) or something.

  • How to disable sort in inputlistofvalues popup

    I'm building custom bpm task list using jdeveloper 11.1.1.7 and in this page i've added input list of values
    this input list of values comes from view object but I've changed its value to my xsd element to save returned value in this elemnt
    Problem happens
         when I open the input list of values popup and try to sort data in the appeared table in the popup
         error says "class cast exception appear"
    I want to avoid this error by disable search in the popup or catch the sort event by java script and cancel it.
    can I make this or no

    this is the error that appears to me
    oracle.jbo.server.ViewObjectImpl cannot be cast to oracle.adf.model.bean.DCDataVO

  • Is it possible to insert a value in a hash map at a perticular index ?

    Hello Techies,
    I have a drop down list which is used to select a contry name. I also contains " All " option which is used to select all countries.
    I am using HashMap for this drop down list for getting corresponding value.
    Now, my requirement is the " All " should display as the first in the drop down list. Hash map didn't support bcoz it is in sorted order,
    Can any one help me with alternative solution ?
    Thanks in advance.
    Javed

    Now, my requirement is the " All " should display as the first in the drop down
    list. Hash map didn't support bcoz it is in sorted order,Rather HashMap doesn't support this because according to the first paragraph
    of its API documentation "This class makes no guarantees as to the order of the
    map; in particular, it does not guarantee that the order will remain constant over
    time".
    Is the drop down list a JComboBox? If so how are you using the hash map?
    And can't you just create an array from the hash map's keys, putting "All" at the
    start?

  • Disabling sort button on the alv list display

    Hi,
       how to disable sort button on alv list display
    thanks

    Fill an itab
    1- Create an itab type SLIS_T_EXTAB.
    2- Populate it with the Function codes you want to exclude ('&OUP', '&ODN').
    3- Pass it as parameter to IT_EXCLUDING
    Regards
    Edited by: Jordi Escoda Ruiz on Apr 24, 2008 10:39 AM

  • Sorting in List Hash Map

    Hi All ,
    I i have the data in below format:
    Name     Age     Skill     Company
    Vass     21     Java     Zylog
    Samy     24     PB     HP
    Lee     18     ADF     CTS
    Reng     16     Java     Info
    I converted this data into java collections List<Hash Map> like this.
    import java.util.ArrayList;
    import java.util.HashMap;
    import java.util.Iterator;
    import java.util.List;
    public class HashMapDemo {
        public static void main(String[] args) {
            // Create a hash map
            List<HashMap> list = new ArrayList<HashMap>();
            HashMap hm = new HashMap();
            hm.put("Name", new String("Vass"));
            hm.put("Age", new Integer(21));
            hm.put("Company", new String("Zylog"));
            hm.put("skill", new String("Java"));
            list.add(hm);
            HashMap hm1 = new HashMap();
            hm1.put("Name", new String("Samy"));
            hm1.put("Age", new Integer(24));
            hm1.put("Company", new String("HP"));
            hm1.put("skill", new String("PB"));
            list.add(hm1);
            HashMap hm2 = new HashMap();
            hm2.put("Name", new String("Lee"));
            hm2.put("Age", new Integer(18));
            hm2.put("Company", new String("CTS"));
            hm2.put("skill", new String("ADF"));
            list.add(hm2);
            HashMap hm3 = new HashMap();
            hm3.put("Name", new String("Reng"));
            hm3.put("Age", new Integer(16));
            hm3.put("Company", new String("Info"));
            hm3.put("skill", new String("Java"));
            list.add(hm3);
            Iterator i = list.iterator();
            while (i.hasNext()) {
                System.out.println(i.next());
    } As per data (table format) i want to sort the data in Column level
    how can i to achieve ?.
    List<HashMap> is type of collection is help to me?
    Any idea?
    Thanks,
    Vass Lee

    Check out Comparator, and use Google to find examples on how to use it.
    http://download.oracle.com/javase/6/docs/api/java/util/Comparator.html
    Still sorting a collection of hashmaps is a bit odd design though. I think you want to create a simple class with properties in stead of a HashMap, then implement Comparable on that class.

  • How to sor hash map

    Hi,
    [b] how to sort hash map contains integer objects,
    HashMap map=new HashMap();
    map.put("1",new Integer("1"));
    map.put("2",new Ineger("2")):
    map.put("3",new Ineger("3")):
    map.put(4,new Integer("4"));
    map.put("10",new Integer("10"));
    map.put("11",new Integer("11"));
    map.put("12",new Integer("12"));
    map.put("20",new Integer("20"));
    map.put(30,new Integer("30"));
    if i am using treemap
    TreeMap map1=new TreeMap(map);
    System.out.println(map1);
    answer is
    1 ,10,11,12,2,20,3,30,4
    but i am accepting the results
    1,2,3,4,10,11,12,20,30.
    what to do
    with regardsshannu sarma[/b]

    This is usual behaviour of a Map. You cannot sort a Set or Map. You can sort a List only using Collections.sort().
    If you want to use a Map which adds all elements according to the order you've added it, then use LinkedHashMap.
    And if you want to capture the keys, use Map.values() which returns an ordered Collection (and after converting it to List, you can sort it).
    Another approach is to create a wrapper object and put it in a List. Then you can use the java.util.Comparator to sort objects in a List.

  • How to store  double  variable in hash map

    i need to store double variable using hash map, but i cant able to store it
    my jsp coding contains
    double et=24,j=5;
    hm.put("stm",st);
    hm.put("etm",et);
    Generated servlet error
    C:\Program Files\Apache Software Foundation\Tomcat 5.0\work\Catalina\localhost\exam\org\apache\jsp\availability_jsp.java:752:
    put(java.lang.Object,java.lang.Object) in java.util.Map cannot be applied to (java.lang.String,double)
    hm.put("stm",st);
    ^
    how to overcome this problem
    thank u in advance

    double etme;
    etme = hm.getDouble("etm");
    i'm getting this error
    C:\Program Files\Apache Software Foundation\Tomcat 5.0\work\Catalina\localhost\exam\org\apache\jsp\editdel_jsp.java:85: cannot resolve symbol
    symbol : method getDouble (java.lang.String)
    location: interface java.util.Map
    etme = hm.getDouble("etm");
    ^
    how to solve it
    plz help me

  • How to find Regular Expressions in a Hash Map

    Hi,
    I Have a hash map with some keys. The Keys are like this(Java.util.regex, Javax.swing.table, javax.swing.text, Java.util.jar, Java.text etc). Suppose if the user gives the search pattern as "text", the o/p should be javax.swing.text and java.text.. How to do it using regular Expressions

    // Sample code...
    import java.util.regex.*;
    public class TestRegex {
        public static void main(String[] args) {
            String test1 = "java.util.regex";
            String test2 = "javax.swing.text";
            String test3 = "java.util.jar";
            String test4 = "java.text";
            Pattern pat = Pattern.compile(".*text.*");
            Matcher mt1 = pat.matcher(test1);
            System.out.println("1> " +mt1.matches());
            Matcher mt2 = pat.matcher(test2);
            System.out.println("2> " +mt2.matches());
            Matcher mt3 = pat.matcher(test3);
            System.out.println("3> " +mt3.matches());
            Matcher mt4 = pat.matcher(test4);
            System.out.println("4> " +mt4.matches());
    }

  • Landmarks display in Maps, how to disable ?

    I am using Landmark feature to plan routes, and i managed to import routes from google earth as landmarks in my E71.
    Three question remaining:
    1. How to disable the display of the landmarks ? Once i have choosen to display a category, i do not know how to disable it again (without deleting the landmarks). Since loading of maps takes more time with landmarks active i would like to switch them off again.
    2. Some landmarks are not loaded (usually around 20% of the landmarks create errormessage and do not have valid coordinates). Can not find the reason... anybody else having this problem?
    3. Does anybody know how to create own symbols? The blue pin-point is to big... would like to have simply a very small point on the map.

    I'm not sure if you can remove your personally saved favourites from the display. There is a choice in Maps 2.0 to enable and disable showing of certain types of "Point Of Interest":
    Options>Tools>Settings>Map>Categories
    But this does not include favourites, and there is no similar option under  the Favourites section.

  • Lost my iphone and located on map it using the fing phone app. The second I located it the phone went offline. Whoever has it knows how to disable the find feature. What are my alternatives? Can at

    Lost my iphone and located it on the map, using the find a phone app. The second I had the location the phone went offline. Apparently, whoever has it knows how to disable the find a phone feature. Do I have any alternatives? Can AT&T or the police track the phone?

    ATT won't unless they are asked to do so by the police and unless a major crime is involved, the police won't request this just for a stolen phone.
    If the iPhone is running iOS 6, sounds like you didn't have the passcode lock feature enabled. Nothing prevents someone from powering the iPhone off and the same for removing the SIM card.

  • IPhone 5S IOS 8. Can't figure out how to disable the "live" location feature within the native calendar app used for mapping/travel time.  Have looked everywhere and it's driving me nuts.  Thanks for any help on where to make the change!!

    iPhone 5S IOS 8. Can't figure out how to disable the "live" location feature within the native calendar app used for mapping/travel time etc.  Have looked everywhere and it's driving me nuts.  Thanks for any help on where to make the change!!

    iPhone 5S IOS 8. Can't figure out how to disable the "live" location feature within the native calendar app used for mapping/travel time etc.  Have looked everywhere and it's driving me nuts.  Thanks for any help on where to make the change!!

Maybe you are looking for

  • Printing multiple PDF files in Windows 7 at once

    When I had Windows XP I could select multiple pdf files in their folder then right click to print.  With Windows 7 this option is no longer there. I have searched everywhere for a solution to this problem.  I am not sure why Adobe (or Microsoft) took

  • Make to Order cost collector

    Hello PP Experts please provide information regarding setting for cost collector against make to order case I have created one order type for cost collector that is working fine for descrete manufacturing  when i create production order through CO01

  • Flickr to web site

    how to add flickr to iweb page like it is done here: http://olavidaswimwear.com/collections.html

  • The Keynote/Quicktime bug which prevents podcast exports from Keynote

    I too have been stymied by the bug which prevents export of .mov files out of Keynote when the presentation contains builds. I spent this weekend recording lectures which I would normally give to medical undergraduates in person but for which I will

  • Airplay between iPad and MacBook Pro

    I am trying to reflect my iPad to my MacBook Pro. I have the 3rd Generation and I am running OS 10.8.2. When I try to connect using Reflector, I get "an error (-6722) while connecting to the AirPlay device "Sandy's MacBook Pro"". What do I need to do