Sorting Values and keeping Keys

Hi,
I was hoping someone might be able to help me. I would like to sort some key value pairs.
I have the following data the key is a string and the value is an int.
"John",26
"George",25
"Ian",33
"Greg",25
I would like to sort the names by age and output them e.g
Greg George John Ian
I have looked at this post using the TreeMap and TreeSet to sort based on values but this seems to only work for Strings. Another problem is that I think tree set needs unique values and in my case they're not unique.
http://forum.java.sun.com/thread.jspa?threadID=634742&messageID=3688987
I was wondering whether someone could help me sort out this problem
Thanks in advance
John

You need to create an Object to encapsulate your data and then sort a collection of those objects. Something like this:
http://forum.java.sun.com/thread.jspa?forumID=31&threadID=598401

Similar Messages

  • Sorting array double or int value and keeping the associated identifier.

    Hi,
    How would I sort an array which contains a double or int value (I know how to do that) but I also want to keep the unique identifier which is associated to array element after the array has been sorted:
    example:
    identifier: 15STH7425042735
    double: 742500.000
    Thanks,
    John J. Mitchell

    Please define an it in form of entity first and then think of operating on structured data.
    a better approach here would be please create an instances of appropriate structured data arrange them in form of a list and then apply specified logic on them
    here is an example which you might think of implementing it and would more appropriate as per your stated requirements.
    public class SampleBean implements Serializable{
       private String uniqueIdentifier = new String();
       private double appValue = 0.0;
       public void setUniqueIdentifier(String uniqueIdentifier){
           this.uniqueIdentifier = uniqueIdentifier;
       public String getUniqueIdentifier(){
          return this.uniqueIdentifier;
       public void setAppValue(double appValue){
              this.appValue = appValue;
       public double getAppValue(){
            return this.appValue;
    }Sample Comparators:
    Comparator comparator4AppValue = new Comparator(){
          public int compare(Object obj1,Object obj2){
                  return Double.compare(((SampleBean)obj1).getAppValue(),((SampleBean)obj2).getAppValue());
    Comparator comparator4UniqueIdentifier = new Comparator(){
          public int compare(Object obj1,Object obj2){
                  return ((SampleBean)obj1).getUniqueIdentifier().compareTo( ((SampleBean)obj2).getUniqueIdentifier());
    };Assuming that you have acquired an Array or List 'N' Elements of SampleBean with appropriate values.
    the belows is the method of how to sort specified Array/List
    In case of array
    SampleBean sb[] = this.getSampleBeansArray();
    // in order to sort using double value inside SampleBean array.
    Arrays.sort(sb,comparator4AppValue);
    // in order to sort using unique Identifier value inside SampleBean array.
    Arrays.sort(sb,comparator4UniqueIdentifier);In case of a list
    List sb = this.getSampleBeansList();
    // in order to sort using double value inside SampleBean array.
    Collections.sort(sb,comparator4AppValue);
    // in order to sort using unique Identifier value inside SampleBean array.
    Collections.sort(sb,comparator4UniqueIdentifier);Hope this might give you some idea of how to go about.:)
    REGARDS,
    RaHuL

  • LOV problem ... returning display-value and not key-value

    Hi. Sorry for my broken English.
    I have a problem with pop-up dynamic LOV.
    I have a simple form called Form A containing item_code and item_name. Users can create, update and delete new item by using this form.
    Another form called Form B has a field called item_code, and the item_code field is a dynamic pop-up LOV field and a query for this LOV is like this;
    select item_name d, item_code r from item_master order by item_code;
    When i create the new record in Form B and use LOV to find and get the item code, LOV works fine
    and it returns key-value to the item_code field.
    But when i try to update the record (I have a link from report page to Form B), value of the item_code field is not the key-value from LOV, but is a
    display-value from LOV.
    Any ideas?
    Thank you.

    Well, from what you have described, this is working exactly as it should. Form B's LOV is intended to retrun the key value but should show the dispaly value. When you go from the report to the form, the key value is being passed (or should be depending on your code) and Form B ought to show the display value.
    So, in short, I would say that Apex is doing what it should. Unless I misunderstand something.
    Bruce

  • PLD and sort value

    Dear Expert
    Happy new year to you
    One customer makes end of the month invoice with all delivery made in the month
    We use sort value and the value is Base Doc reference in INV1 and we group by, the delivery note number is selected
    At each group we can see as header the Delievrey note number
    But we also want to see on the same header the date of delivery (actdeldate) and customer ref (BaseAtCard)for each group of delivery
    How is it possible with PLD what function to use.???
    We use SAP BO 2007 SP01 PL11

    Hi,
    PLD is a very simple tool. You probably need Crystal Report to achieve your goal.
    Thanks,
    Gordon

  • ALV: How do I suppress repeating values and page breaks on printed output?

    Good day, everyone!
    First, I've done a LOT of searching trying to find the answer to my question, but I'm not finding an answer.  If this has already been answered and you can point me to a URL, I would appreciate it.
    Here's my issue:  I have a rather simple ALV report.  It has the columns of Person ID, Personnel Number, For Period, In Period, and Amount.  I sort by Person ID and Personnel Number, and if the value repeats on the next line of the report, I want to suppress it (make it blank).
    I thought the answer was in the following code, where I set the GROUP attribute to asterisk:
      CLEAR sortcat_ln.
      sortcat_ln-spos      = '1'.
      sortcat_ln-fieldname = 'PERSONID_EXT'.
      sortcat_ln-up        = c_true.
      sortcat_ln-group     = '*'.
      APPEND sortcat_ln TO sortcat.
      CLEAR sortcat_ln.
      sortcat_ln-spos      = '2'.
      sortcat_ln-fieldname = 'PERNR'.
      sortcat_ln-up        = c_true.
      sortcat_ln-group     = '*'.
      APPEND sortcat_ln TO sortcat.
    It looks PERFECT on the screen -- the values are suppressed if they repeat, and everything appears together on one screen.  However, when I print the report, two things happen:  1) The values repeat on each row, even if they are the same, and 2) I get a page break after each Person ID / Personnel Number combination.
    I now realize that I can't use the GROUP attribute.  Is there some other way in ALV to blank these repeating values and keep all the rows together on one page, rather than page breaking after each value change?
    Thanks!
    Dave

    Hi
    Same requirement i had before, when i try to print preview. the output of the grid display is in grouping is ok, but when i print preview or print it doesnt cater the grouping and page breaks, so what i did i modify the internal table use in alv , after hitting the print preview/print with the format desired by the user. you can do that in user-command. see code below
    FORM user_command USING r_ucomm TYPE syucomm
                            rs_selfield TYPE slis_selfield.
      DATA lt_sort TYPE lvc_t_sort.
      CASE r_ucomm.
        WHEN '&RNT_PREV' OR '&RNT'.
          t_final_x[] = t_final[].
          PERFORM clear_redundant.
          PERFORM set_sort_criteria USING lt_sort.
        WHEN '&F03' OR '&PRINT_BACK_PREVIEW'.
          t_final[] = t_final_x[].
        WHEN OTHERS.
      ENDCASE.
    ENDFORM.                    "user_command
    hope it helps

  • Sorting Map on values rather than keys

    Is it possible that I can have a Map which is sorted based on values rather than keys ?
    If not is there an alternative.
    Basically I have keys as strings and values as integers.
    The values keep incrementing and at the end I want to get the top 50 keys based on the values.

    Sorting a Map by values is not a good idea, I did something similar before, it doesn't support the design, but it is better in performance, which is implementing a custom class (name it Record) that contains two members: key and value, create a record and insert it into a SortedSet e.g. TreeSet.
    make sure to do the following:
    1. This custom class must implement Comparable and compares two values
    2. Override euqlas method and accept strings (check using instanceof) then compare it to the key so you can retrieve the records using the key (to let it work as a map)
    Now you have a sorted set with key,value pairs, use the add method to insert a new pair, use the remove to retrieve the desired object and the set is already sorted :)
    Regards
    Mohammed

  • Read and sort values present in .ini file

    Hi all,
    I have a .ini file in which a set of modules with there order of execution is mentioned.I want to get all these values sorted as an array so that I can proceed with the execution of each in the order mentioned.The module list in the .ini file looks like this:
    Here, digits represent the order of execution of module.
    I should get output as an array with following values:
    1 MNO
    2 DEF
    3 STU
    4 PQR
    5 GHI
    6 VWZ
    7 ABC
    8 JKL
    I know about config data and read key vis but since the module list is huge I dont know how to write an efficient code for this.All suggestions are welcome.
    Thanks.
    Solved!
    Go to Solution.

    The snippet below should be very close to what you want.

  • Key differencess bet'n Altrnative condtion base value and Alternative calcu

    Hi All
    I read many times even though I have dought in pricing where in, differentating Altrnative condtion base value and Alternative calculation type.
    I know these two are forumalas.
    I am looking for key differencess bet'n Altrnative condtion base value and Alternative calculation type
    Where & which senario I can make out  the differnces bet'n Altrnative condtion base value and Alternative calculation type.
    Please explain in details which can keep in mind for long run...
    Thanks in advance.
    Regards,
    Ramkrishna.

    Hi Rama krishna
    go thru this....u can make difference and will have idea too
    AltCty - Condition formula for alternative calculation type:
    It is again a Routine that is written by ABAP Consultant.
    It is an alternative formula for the condition type that can be used instead of standard
    formulas.
    For example, let us take the Profit Margin which can be both + / - , so here this
    routine will help us in generating the value which can be either + or -. Profit margin is
    not a condition type so it cannot be classified as +ve or -ve in the V/06.
    Ex.: 950 0 Profit Margin 11.
    So we assign 11 - Profit Margin.
    If new routines are to be defined we follow the procedure given below.
    Go to T.Code: VOFM. - Maintain Requirements & Formulas
    Click on the "Formulas" and then on the "Condition Values".
    We have a list of routines, we can ask ABAP consultant to create new routines
    based on the client requests. And we assign the application type.
    AltCBV - Alternative formula for condition base value:
    Formula for determining the condition basis as an alternative to the standard.
    It is again a Routine that is written by ABAP Consultant.
    It is used as a basis to calculate value of the condition type instead of using it from the
    "FROM" column.· Ex.: Freight - KF00.
    Freight is calculated based on weight, volume etc. and not on the base price. In pricing
    there is no entry of weight from which the value can be referred like we do for
    discounts using base price. We have to get the value from the Material master.
    In this column we can mention the value as 12 - Gross Weight or 13 - Net Weight.
    During pricing, the system will consider the value that is mentioned in this column and
    determine the freight based on this value.
    Suppose we have Net weight: 100 kgs and Gross Weight: 150 kgs. And if we mention
    13 in this column then the Freight condition KF00 will be calculated using the weight
    as 100 kgs.
    Thanks and regards
    Chandra

  • No repeated values and in ascendant sort

    Hi all,
    I'm trying to put this:
    SELECT DISTINCT month FROM Concert ORDER BY month ASC;
    (no repeated values and in ascendant sort) into EJB-QL. This is what I've worked out:
    SELECT DISTINCT OBJECT(o)
    FROM Concert AS o
    ORDER BY o.month ASC
    (month is a field in the bean )
    But this (and several tries later) doesn't work.
    What's wrong with it??
    The query is for a findAll method -without- input parameters which returns a collection, is here the error??? If so, how can I solve it?
    I'm totally lost and frustrated, I'd really appreciate some light
    Thanks a lot in advance

    Your query is currect if table name and attribute name are currect.
    Can you write what type of error is comming?

  • How to create a PDF with substituted key-value and table-values using a template language

    I have about 50 key-values and 10 table-values that I want to substitute into a formatted report template (language can be anything standard, would create a small number of these templates) and then use an Adobe tool to substitute the values into the template and produce a PDF. Preferably the template language would permit some basic conditional logic (if <key #> has value <value> then <show key label here> and <key value here> in close spatial proximity on the form) and permit embedding of a static graphic logo, text with fonts/styles, etc. to produce a polished report but also handle pagination (e.g. enable page breaks or numbering) to be handled automatically.
    What is a recommended template language and product to accomplish this?

    Are you thinking of something like a blank form that you can enter information into, save, and send to another user? If so, what you want is possible. If you want more information, post again and include more details about how you want to use it and how the recipient will use it.

  • After download itunes installation began in windowx xp near the end of the installation the message says: it was not possible to write the value to the key Software / Classes / .mpg / OpenWithList / iTunes / .exe. Already reinstalled 3 times and always sa

    After download itunes installation began in windowx xp near the end of the installation the message says: it was not possible to write the value to the key Software / Classes / .mpg / OpenWithList / iTunes / .exe.
    Already reinstalled 3 times and always says the same message.
    thank you

    Only two had virus on windows XP this week and wiped them with Avast. The itunes asked me to install the update, and so I did. but it always gives me that message.

  • How to grab value on command and keep it available?

    This should be obvious but I don't see it!
    I want to grab a value on a wire whenever the user presses a button, and hold that value for use at any time.
    So for instance I can rezero an instrument when the user presses the button, by grabbing the instrument output at that time, and by displaying the difference between current instrument output and the grabbed value.
    I tried wiring the output of a select node back to one of its inputs to hold the value, and connecting the wire to be grabbed from to the other input, and tying the button momentary output to the control input on the node, but it doesn't like having its output fed back.
    Thanks!

    Mike, I think I irritated you, and I'm sorry. I have a big machine I programmed years ago in Forth and Assembly, and am reworking it in LabVIEW to be more in step with the rest of the world, but am finding it surprisingly hard and a little intimidating. Many things that were easy before still look hard or impossible, at least at first. I'm irritated at how difficult some things seem, and I let the post show it, so - I appologize!
    >First of all your questions betray a basic lack of understanding of how LV works. For example, in LV you don't copy data from one memory location to another.
    It's true, I don't have a basic understanding of how LV works. I hear about dataflow, and gather that implicitly this is trying to make a stack-oriented system map to our human ability to navigate through physical spaces, whereas systems that use more named variables are using our language abilities instead. I bet you do, though, copy data from one memory location to another, whether it's apparent or not, whether you use names and assignment statements or not. I think to tare a gage you must copy the present value to someplace for storage. I have stopped looking for the "copy" node, but still have to accomplish the same effect, and have to do so at an arbitrarily specified time.
    >And if you don't know how to run a VI you apparently haven't completed the first exercise.
    I know how to run some VI's. Somebody else's VI that gives a version compatibility error, no, I don't know how to run that, not without digging into it further. Which I will do. Feel free to ignore this thread until I report back on that. Or longer, of course.
    >I would suggest that you take some time going through the "Getting Started" materials that come with LV and perhaps take a class.
    Yes. I went through a bunch of "Getting Started" materials, wrote and ran a hundred or so VI's, and took a week of classes from NI. But there still seem to be big pieces missing.
    >Second when you do have code that you have specific questions about, post the code so we can comment on it.
    OK, here are two VI's that work together: AnalogInstrument01 has a measurement that I now offset with the constant "53.5". Tester01 sets up a task and executes a loop containing AnalogInstrument01, passing that task into it and getting values of the scaled and offset measurement returned to it. In my project I will have other bigger VIs like Tester01, running an asynchronous loop containing AnalogInstrument01 plus others like it. Some are counters that may not miss a beat. Some take varying time to execute. I must maintain one to one correspondence between all the measurement events within that loop. I am pretty sure it would compromise the goodness of data that my system generates to move away from this asynchronous calling loop strategy.
    I want to be able to readjust the offset instead of using 53.5 all the time. However, when it's tared, it should appear similarly tared, and behave the same way, to any VI that calls it. Therefore I think this tare should be part of the AnalogInstrument VI and not part of the other parent VIs that call it. However, the instrument must be ready for on-demand reading by a parent asynchronous loop, therefore (I think) not having its own while loop. Can somebody suggest a way of grabbing and holding the value here?
    It's obvious how to do it if you can have the loop in the same VI as the tare value. You just pass the tare value around in the shift register for that loop. I added that example as AllOneHasTare01, which reads and tares just fine. Only problem is you can't call it from another asynchronous loop because its own loop keeps it busy.
    To be more clear about what I think I need, you can imagine doing this in an object oriented text language instead, say C++. You'd create a Measurement class with a tare method. The constructor would load a private tare field with zero at object instantiation. There's be a tare method that copies the output of the measure function into the tare field. There'd also be a measure method that returns the difference between a fresh raw measurement and the tare field value. Then another class like Tester would own an instance of Measurement and would call the measure function from inside its loop. This sounds easy - but how would I do it in LabVIEW?
    Attachments:
    AllOneHasTare01.vi ‏16 KB
    AnalogInstrument01.vi ‏17 KB
    Tester01.vi ‏13 KB

  • How can i do to see the master and text values of the Key figure 0UNIT

    Hi gurus,
    How can i do to see the master and text values of the Key figure 0UNIT, please step by step, i m in the key figure 0UNIT but i want to see if the UNIT  for example BX = BOX, something like this is that i want to check,  thanks!

    If you look at the unit tables, you will see the values and texts.  It's in SPRO, not in RSA1.  My access is limited on my system here, but the documentation says to go to t-code CUNI.  I believe in that tcode you can look at all of the unit equivalencies and what each unit's text is ..... like an ea means each; KG = Kilogram; etc...
    I am on an 3.x system, so in SPRO I go to BW CIG=>General Settings=>Check units of measurement.
    Brian

  • Getting the UPDATEd value and its primary key

    I have two procedures, proc1 and proc2.
    In proc1 there is an update happening like
    CREATE OR REPLACE procedure proc1
    as
    TYPE NumList IS TABLE OF employees.employee_id%TYPE;
    enums NumList;
    TYPE NameList IS TABLE OF employees.last_name%TYPE;
    names NameList;
    BEGIN
    UPDATE emp set sal=900 WHERE department_id = 30
    RETURNING employee_id, last_name BULK COLLECT INTO enums, names;
    DBMS_OUTPUT.PUT_LINE('Updated ' || SQL%ROWCOUNT || ' rows:');
    FOR i IN enums.FIRST .. enums.LAST
    LOOP
    DBMS_OUTPUT.PUT_LINE('Employee #' || enums(i) || ': ' || names(i));
    END LOOP;
    END;
    /In proc2 which is getting executed just after proc2 i want to SELECT the sal column values and its primary keys(employee_id) which got updated in proc 1.
    How can i achieve this?

    add two out parameters from proc1 so that you can pass them into proc2 (obv. you'd need to add two in parameters to proc2 if they aren't there already)

  • I have an iphone that i have been waiting for 50 days for orange to unlock and keep getting fobbed off with promises to sort it out, i have made so many calls and getting really frustrated now. Does anyone know what the procedure is for an unlock

    I have an iphone that is locked to orange and have been waiting over 50 days now for it to be unlocked and keep getting fobbed off with promises to sort it out. I dont know how many calls have been made and am getting really frustrated now. Does anyone know how apple are involved with the unlock as  im jst not getting any answers from orange and they just keep saying they dont know why its takng so long

    If it is Orange Uk then no surprises
    They locked it originally and it is their gift to unlock ....usually in their own time.
    This is how it should work
    http://support.apple.com/kb/HT5014

Maybe you are looking for