How to sort HashMap by values?
?
You can create a TreeMap out of your HashMap using the values as the key. Just remember that the keys can not be duplicates.
Bosun
Similar Messages
-
How to sort via multi value parameter in ssrs
I have a parameter with multi values. when the user selects ,he get of options like acount name, first name, last name.
so if user selects firstname , the data has to sort by firstname.
if he selects acount name , the data has to sort by account name.
please help me how to sort the data using parameter with multivalue? in ssrs 2008.
Thank you?Hi Venku,
Based on your description, it seems that you create a parameter with available values and you want to sort the report data based on the parameter value. If the available values are the field names in the report, you can try to open the Tablix properties
dialog box and specify the sort expression on "Sorting" tab as follows:
=Fields(Parameter!parametername.value).value
If the parameter allow multiple values and you want to sort the report data by more than one field, for example, sort the report data by "accountname" and then by "firstname", please add two sort expressions as follows:
=Fields(Parameter!parametername.value(0)).value
=Fields(Parameter!parametername.value(1)).value
If you have any question, please let me know.
Regards,
Fanny Liu
Fanny Liu
TechNet Community Support -
How to sort the arry value in ascending order
I have a string array where i need to sort the below values in ascending order in the same format...can anyone give me clue on this?
9.3
3.1
9.1
19.1
19
9.4
9.1.1
the sorted order should be
3.1
9.1
9.1.1
9.3
9.4
19
19.1You may have easier luck writing your own comparator for this. These are headings in a table of contents, right?
Write a comparator that tokenizes a string on the '.' character, or use a StringBuffer to remove them, and then order the elements according to the combined numbers. Since alphanumeric would order this list as you want it anyway you could just order that way once the '.' are removed.
In other words your comparator would do this in the "compare" method:
public class MyComparator implements Comparator, java.io.Serializable {
private static Comparator stringComparator = java.text.Collator.getInstance();
...constructor(s), your own private "instance" variable of type MyComparator, a getInstance() method of your own, yadda yadda...
public int compare(Object item1, Object item2) {
try {
value1 = removePeriods((String)item1);
value2 = removePeriods((String)item2);
if (value1 == null) {
return (value2 == null) ? 0 : (-1);
return compare(value1, value2);
} catch (ClassCastException cce) {
System.err.println("Wrong Object Type, JackAss!");
protected int compare(String str1, String str2) {
return MyComparator.stringComparator.compare(str1, str2);
private String removePeriods(String value) {
StringBuffer sb = new StringBuffer(value);
int decimalIndex = value.indexOf('.');
while (decimalIndex != -1) {
sb.delete(decimalIndex, (decimalIndex + 1));
} -
How to sort the characteristic values in layout
Hello,
I wont to use a layout with key figs in data columns and two characteristics in lead columns. The problem is that the sorting of first characteristic values is displayed in alphabetical order. How can I change the order to another exact defined combinations for characteristic values?
I read the thread with the same problem (see below the link), but the solutions are not satisfacroty.
Has anyone another idee?
Thanks for any help!
Larissa BräutigamHi Larissa;
I had the same problem and they propose this:
Attributesu0092 order that the system displays in the Planning Layout
That was not the solution presented to the customer. Because of system performance, a programmer was there and created a VBA code. But I wasn't there so I don't have the code.
regards -
How to sort select highest value in column ?
Sort by
highest text value in column (name)
example
column : ID name
address before ID
name
address after
1 jony street1 1
muhmuod street3
2 ali street2 2
jony street1
3 muhmuod street3 3
ali street2SELECT Row_Number() over (Order by Name desc) as ID
, name
, address
from tbl
order by name desc;
Russel Loski, MCT, MCSE Data Platform/Business Intelligence. Twitter: @sqlmovers; blog: www.sqlmovers.com -
How to Sort based on value of a field?
Hello,
I've been trying to sort the information on an invoice by line description only when interface line context = 'PROJECTS INVOICES'. Other wise (for other interface line contexts), it should sort by line number, which is the default sort.
I've been using the following syntax
<?for-each:LIST_G_LINES?><?if:INTERFACE_LINE_CONTEXT='PROJECTS INVOICES'?><?sort:LINE_ITEM_DESCRIPTION?><?end if?>
But I'm getting the following error
Caused by: oracle.xdo.parser.v2.XSLException: <Line 88, Column 87>: XML-22047: (Error) Invalid instantiation of 'xsl:sort' in 'xsl:if' context.
Any suggestions are welcome.
Thank you
SriniRainer,
I have put the following code and the invoice is still getting sorted by Line Number
<?xdoxslt:set_variable($_XDOCTX,'order', 'LINE_NUMBER')?>
<?if:INTERFACE_LINE_CONTEXT='PROJECTS INVOICES'?>
<?xdoxslt:set_variable($_XDOCTX,'order', 'LINE_ITEM_DESCRIPTION')?>
<?end if?>
<?for-each:LIST_G_LINES?>
<?sort:./* [name(.) = xdoxslt:get_variable($_XDOCTX, 'order')] ;'ascending'?>
Regards,
Srini -
Want to sort HashMap based on Values with duplicate values
Hi. I have a requirement to sort the HashMap based on the values not on the keys. My HashMap contains the values which are duplicates. My program is some thing like this.
Map m = new HashMap();
m.put ("Gosling", new Integer(2000));
m.put ("Joy", new Integer(2000));
m.put ("Schwartz", new Integer(3000));
m.put ("Bracha", new Integer(4000));
m.put ("Gafter", new Integer(3000));
still i need to sort HashMap based on the values. How can i do it. I want the output some like this.
Gosling 2000
joy 2000 (may be interchanged)
Schwartz 3000
Gafter 3000 (Same as above)
Bracha 4000
Thanks.I found syntactical problems with above mentioned code.
Here is edited working version:
* test sortMap
public void testSortMap () {
Map m = new HashMap();
m.put ("IGGHHG", new Integer(232353453));
m.put ("ASDF", new Integer(345555000));
m.put ("DSF", new Integer(345555000));
m.put ("XYZ", new Integer(45555555));
m.put ("AAA", new Integer(0));
ArrayList outputList = sortMap(m);
int count = 0;
count = outputList.size();
while(count > 0) {
Map.Entry entry = (Map.Entry) outputList.get(--count);
System.out.print("Key:" + entry.getKey());
System.out.println("\tValue:" + entry.getValue());
* This method will use Arrays.sort for sorting Map
* @param map
* @return outputList of Map.Entries
public ArrayList sortMap(Map map) {
ArrayList outputList = null;
int count = 0;
Set set = null;
Map.Entry[] entries = null;
// Logic:
// get a set from Map
// Build a Map.Entry[] from set
// Sort the list using Arrays.sort
// Add the sorted Map.Entries into arrayList and return
set = (Set) map.entrySet();
Iterator iterator = set.iterator();
entries = new Map.Entry[set.size()];
while(iterator.hasNext()) {
entries[count++] = (Map.Entry) iterator.next();
// Sort the entries with your own comparator for the values:
Arrays.sort(entries, new Comparator() {
public int compareTo(Object lhs, Object rhs) {
Map.Entry le = (Map.Entry)lhs;
Map.Entry re = (Map.Entry)rhs;
return ((Comparable)le.getValue()).compareTo((Comparable)re.getValue());
public int compare(Object lhs, Object rhs) {
Map.Entry le = (Map.Entry)lhs;
Map.Entry re = (Map.Entry)rhs;
return ((Comparable)le.getValue()).compareTo((Comparable)re.getValue());
outputList = new ArrayList();
for(int i = 0; i < entries.length; i++) {
outputList.add(entries);
return outputList;
}//End of sortMap -
How to Sort Dimension in Pivot Table via Order Column which is changing like Factual values
Hi,
Recently in of our product offerings we got stuck on this following question:
How to Sort Dimension based on the Order Value which Keeps Changing with Factual Values??
We have a data source laid out as (example)
In the above the “Order” columns are changing per
Company/(DimensionA) for DimesnsionB.
Instead what we want is: (But only if we can get the following result without putting the “Order” Column in the “Values” Section.
If there are any configurations that we can make to our power pivot model for the similar data set so that the
DimesnionB in this case can be sorted by the Order column, would be greatly helpful to us.
Sample File:
http://tms.managility.com.au/query_example.xlsx
Thanks
AmolHi Amol,
According to your description, you need to sort dimension members in Pivot Table via order column, and you don't want the order column show on the Pivot table, right?
Based on my research, we can sort the data on the Pivot table based on one of the columns in that table, and we cannot sort the data based on the columns that not existed on the Pivot table. So in your scenario, to achieve your requirement, you can
add the column to pivot table and hide it.
https://support.office.com/en-gb/article/Sort-data-in-a-PivotTable-or-a-PivotChart-report-49efc50a-c8d9-4d34-a254-632794ff1e6e
Regards,
Charlie Liao
TechNet Community Support -
Sorting HashMap based on values
I need to sort a hashmap based on the values, but also need to keep the keys available for retrieving the values.
Example:
key value
1 c
2 a
3 b
Desired Result
2 a
3 b
1 c
Thanks for your help.You can do this by getting all the Map.ENTRY values in a HashMap object then using a custom Comparator object to sort them by value.
like this:
HashMap hashMap = // your HashMap
Set entrySet = hashMap.entrySet;
/* Now add them into a list and use the Collections
* class to sort them.
ArrayList list = new ArrayList();
list.addAll(entrySet);
Collections.sort(list, yourSpecialComparator);Hope this helps. -
How we can sort subtotal results value in abap alv report
Hi, How we can sort subtotal results value in abap alv report
Thanks a lot for your code
but i am still getting double and weird results.
Subtotal IN PARTY KGS TOTAL VALUE
1 40008 3,141.20 192,799.00
1 40008 16,681.06 1,908,659.00
Subtotal 1 19,822.25 2,101,458.00
10 40022 4,590.60 531,228.00
10 40022 3,448.27 377,173.00
Subtotal 10 8,038.87 908,401.00
100 40010 270.172 19,852.00
Subtotal 100 270.172 19,852.00
101 40036 752.898 61,051.00
101 40036 207.586 19,431.00
Subtotal 101 960.484 80,482.00
102 40048 325.936 32,154.00
102 40048 264.32 19,364.00
Subtotal 102 590.256 51,518.00
103 40066 216.134 18,088.00
Subtotal 103 216.134 18,088.00
104 40001 231.96 16,986.00
Subtotal 104 231.96 16,986.00
105 40021 585.918 65,461.00
105 40021 108.683 15,825.00
Subtotal 105 694.601 81,286.00
106 40046 209.777 15,341.00
Subtotal 106 209.777 15,341.00
107 40043 167.353 14,755.00
Subtotal 107 167.353 14,755.00
108 40046 153.023 14,343.00
108 40046 342.348 32,223.00
Subtotal 108 495.371 46,566.00
109 40008 184.085 13,483.00
Subtotal 109 184.085 13,483.00
11 40011 5,275.63 524,232.69
11 40011 6,723.28 643,911.82
Subtotal 11 11,998.90 1,168,144.51
110 40067 142.113 13,333.00
110 40067 492.883 44,428.00
Subtotal 110 634.996 57,761.00
111 40040 118.961 13,190.00
111 40040 492.433 60,029.00
Subtotal 111 611.394 73,219.00
Edited by: Timaji Sawant on Feb 16, 2012 12:16 PM
Edited by: Timaji Sawant on Feb 17, 2012 9:27 AM -
Hi all,
I have a hashMap that I need to sort into descending order by value w/out losing its key.
Example Hash:
301 | 12
302 | 48
303 | 10
304 | 20
Desired Results:
302 | 48
304 | 20
301 | 12
303 | 20
I have searched the forums and found some similar situations but nothing exactly like what I am trying to do.
I started out w/ this:
public void sort(HashMap hash)
List sortedList= new ArrayList(hash.values());
Collections.sort(sortedList);
However I lose my key & the arraylist is sorted ascending...
Any help would be appreciated!You might extract the entry set, convert that to an array and use the static sort method of java.util.Arrays that accepts a Comparator. Implement a Comparator that looks into the entries (which are instances of Map.Entry that contain both key and value) and compares the values for whatever sorting order you want to establish.
You might then iterate over the sorted array and place the values back in a HashMap to regain access via keys. Or maybe you just store Integer instances there, giving the position of the corresponding entry in the array, from where you find the values or keys - whatever you need on each access.
Or you place that HashMap and the array in a new class that maintains them, allows to trigger sorting when needed, and provides access via key or position (internally using the array or the map as needed).
If that class should behave exactly like a map, i.e. implement java.util.Map and ALSO provides the usual iterators and keyset, valueset and entry-collection etc... with all its related behaviors, then beware: That's a major programming task!
Look at the sources of java.util.HashMap if you need to do that. Else do not implement java.util.Map and just implement the functionality that you really need at that point. -
How to Sort one key figure values in two column based on single char
hi gurus,
I would really appreciate if some one can help me out with my question.
I have to design a query based on a Multiprovider built on three ODS, Purchasing, Confirmations & Invoic ODS
Purchase order Value and Number data in PO ODS, and confirmations is in CONFODS, Invoice Values in INV ODS,
The design of the requirement is
Vendor --> PO --> Material PO Value --> Text PO Value --> Confirmation value --> Invoice value
There are Two POS 1. Material PO & 2. Text PO
I need to display all the Purchase orders for a vendor and in different columns i need to display the value of the Material PO and Text PO and their Confirmation Value and how much is the invoiced value for every PO.
Can anybody tell me what should i do in the Query Designer to display the necessary values.
Thank youHi william,
When i put in the PO KF in the column and also the Confirmation KF in other Column it either shows me # for both the entries or it shows me values in only one of the column
if PO is displayed the Confirmation is not displayed and if Confirmation is displayed PO values are shown as # i dont know what wrong i am doing.
if you have idea can you tell me what i should do when i want two different values from two ODS if there are no characteristics that are matching in either of the ODS should i go for Multi Provider and if so how should be my designing. i would really appreciate if you can tell me taking a scenerio.
Thanks -
How to sort options by text if option value is int & option text is string?
Hi All,
I've an application in which on a jsp page has two html:select (listBox). Further 3 buttons are provided namely ADD,REMOVE and SAVE. On click of ADD the selected option from listBox 1 is transferred from listBox 1 to listBox 2. On Click of REMOVE the selected option from listBox 2 is transferred from listBox 2 to listBox 1.
My problem starts from the next step. When an item is transferred from source to target listBox. The target listBox should be sorted alphabetically. Now in html:option values are IDs which are int and text is name which String. And the sort method is called upon array of options, which sorts according to value and requirement is that it should sort by text.
Somebody please help me regarding this problem. Waiting for help.... Thanks in advance.Hi All,
I've an application in which on a jsp page has two html:select (listBox). Further 3 buttons are provided namely ADD,REMOVE and SAVE. On click of ADD the selected option from listBox 1 is transferred from listBox 1 to listBox 2. On Click of REMOVE the selected option from listBox 2 is transferred from listBox 2 to listBox 1.
My problem starts from the next step. When an item is transferred from source to target listBox. The target listBox should be sorted alphabetically. Now in html:option values are IDs which are int and text is name which String. And the sort method is called upon array of options, which sorts according to value and requirement is that it should sort by text.
Somebody please help me regarding this problem. Waiting for help.... Thanks in advance. -
How do I change the value of the Order By field in an MP3 file?
good day Guys,
I'm new here in the forum and I have a question that is "breaking" the order of my songs and my head too ...
How do I change the value of the Order By field in an MP3 file?
for example, in the photo below, the song "The Bad Touch" is coming BEFORE the song "A Little Respect", this happens because of the Name field to Order ...
My "problem" is in the photo below, the "tab" Order, iTunes will not let me erase what is written in the "Sort As" ...
I've been "collecting" several songs over SEVERAL years
I'm currently with more than 1,500 songs on HD and several backups on DVDs and external hard drives and I think, download it again, will be a "little" laborious and boring
I DON'T WANT to be filling the tags of songs (name, singer, CD, year, etc.)
I have used the program Mp3tag to remove the music tags
I've tried to download the song again and go through Mp3tag program as if it were a new song
I've changed the music access permissions, folder and even entire hard drive (my Windows has only one user)
I've tried to catch the song again, from a previous backup
I've tried to create a copy of the file at iTunes own
I've tried to create a new music file in a music recording program
NOTHING of what I did above resolved
-> I'm using Windows 7 64-bit Ultimate
-> I'm using iTunes 12.1.1.4 for 64-bit Windows
-> My iPad is the third generation (a little old, I know) with Wi-Fi and 3G, but it has served me VERY WELL
-> The iPad is updated with iOS 8.1.3 and is not unlocked
I'm sorry for the GIANT post, but well, I think I could explain as much as possible and for my English, too bad, by the way, I'm from Brazil and I'm using Google translator
Hugs and await answers,
Paulo Ricardohello turingtest2,
my language is Brazilian Portuguese (there are some little differences between Brazilian Portuguese and the Portuguese of Portugal, but nothing that interferes with the script)
at this time, I'm managing songs manually, I don't know if this will interfere with the execution of a script or command
as I picked up this iPad recently, I still don't understand how to set up the iTunes Music Library and the person who gave me, told me it was easier to put the songs manually
as you said, in my iTunes, 95% of the songs are with ALL the blank fields, including the Name to Sort field, only songs that begin with a/an/the standing with the Name to Sort field filled with name of the song, without the a/the
I do not know what to do...
I want to learn to ride the iTunes Music Library, that my work is less
you know any site that teaches create/manage my iTunes Music Library?
this site/forum may be in English, no problem
thanks for all your help and the help of others who responded to my request -
How to Sort JTable data using Multiple fields (Date, time and string)
I have to fill the JTable data with some date, time and string values. for example my table data looks like this:
"1998/12/14","15:14:38","Unicorn1","row1"
"1998/12/14","15:14:39","Unicorn2","row2"
"1998/12/14","15:14:40","Unicorn4","row3"
"1998/12/17","12:14:12","Unicorn4","row6"
Now the Sorted Table should be in the following way:
"1998/12/17","12:14:12","Unicorn4","row6"
"1998/12/14","15:14:40","Unicorn4","row3"
"1998/12/14","15:14:39","Unicorn2","row2"
"1998/12/14","15:14:38","Unicorn1","row1"
ie First Date field should be sorted, if 2 date fields are same then sort based on time. if date and time fields are same then need to be sorted on String field.
So if any one worked on this please throw some light on how to proceed. I know how to sort based on single column.
But now i need to sort on multiple columns.So what is code change in the Comparater class.
Thanks in advance.. This is urgent....I think your Schedule objects should implement Comparable. Then you can sort your linked list using the Collections.sort() method without passing in a Comparator.class Schedule(Date date, String class) implements Comparable
public void compareTo(Object obj)
Schedule other = (Schedule)obj;
return date.getTime() - other.getDate().getTime();
}
Maybe you are looking for
-
Wifi Driver is not working after upgrading windows7 to windows8 in MAC BOOK PRO2012
Hi, Recently I installed windows7 in my MacbookPro2012.Yesterday I upgraded windows7 to windows8.All the basic drivers are working properly except wifi connectivity. It is recognizing the available wireless networks,but when Iam trying to connect to
-
Router blocks random IP or Domain Addresses
This appears to be a rather unusual problem and has only been noticed in the past month. Suddenly without any apparent warning, certain web sites are no longer accessible. This was first noticed when I was unable to access my pop3 email from the www.
-
How to import Ms Access database in Oracle 11g
how to import Ms Access database in Oracle 11g
-
When exporting to pdf in Photoshop CC in CMYK, Acrobat opens it with a blank page and the message that it's out of memory. Exporting the same file as RGB opens fine. Any ideas? Exporting as CMYK has worked fine in all the previous versions of Photosh
-
What about if I want to compile a run form on the web with oracle forms 6i. The only thing I need to do is Run form on the web and thats all? Where must I place the files? and which files? The clients needs some software installed?