logo
down
shadow

How can I sort a map with string key? like (1 foo , 2 foo)


How can I sort a map with string key? like (1 foo , 2 foo)

By : thangam
Date : November 25 2020, 04:01 AM
Does that help Use a TreeMap with a custom Comparator.
By default, the String Comparator compares Strings lexicographically and this is the reason why you see an order like this {"1", "10", "11", ..., "2", "20"}.
code :
TreeMap<String, Indicador> sortedMap = new TreeMap<>(new Comparator<String>() {
    public int compare(String string1, String string2) {
        return Double.parseDouble(string1) - Double.parseDouble(string2) < 0.0 ? -1 : 1;
    }
});


Share : facebook icon twitter icon
Unable to sort string array in android, Arrays.sort causes fatal exception

Unable to sort string array in android, Arrays.sort causes fatal exception


By : Vijay Sharma
Date : March 29 2020, 07:55 AM
will be helpful for those in need 08-03 00:45:25.287: E/AndroidRuntime(676): Caused by: java.lang.NullPointerException
Basically you are creating a big array of nulls and then trying to sort it -> NPE.
Sort a two dimensional String array with Arrays.sort based on a chosen column

Sort a two dimensional String array with Arrays.sort based on a chosen column


By : foram
Date : March 29 2020, 07:55 AM
help you fix your problem I have a two dimensional array filled with strings in Java. I want to be able to sort the entire array relative to the column I have chosen to sort by. , Sure, just pass the column index in as a parameter of the comparator.
code :
class ColumnComparator<T extends Comparable<T>> implements Comparator<T[]> {
  private final int column;

  ColumnComparator(int column) { this.column = column; }

  @Override public int compare(T[] a, T[] b) {
    return a[column].compareTo(b[column]);
  }
}
class ColumnComparator implements Comparator<String[]> {
  @Override public int compare(T[] a, T[] b) {
    return a[1].compareTo(b[1]);
  }
}
Sort list by passing string value for wanted field, and second sort by date in JavaScript

Sort list by passing string value for wanted field, and second sort by date in JavaScript


By : Nick Manley
Date : March 29 2020, 07:55 AM
Does that help This is a proposal with a privileged sorting for the given key/value pair.
Features:
code :
var list = [
    { date: "2005-04-01", position: 12, worker: "John", prop: "k11" },
    { date: "2006-02-01", position: 72, worker: "John", prop: "k12" },
    { date: "2005-09-06", position: 42, worker: "Aleks", prop: "k43" },
    { date: "2004-07-02", position: 12, worker: "Mark", prop: "k12" },
];

function setCondition(condition) {
    var key = Object.keys(condition)[0],
        value = condition[key];
    return function (a, b) {
        function x(o) { return -(o[key] === value); }
        return x(a) - x(b) || b.date.localeCompare(a.date);
    }
}

document.write('<pre>' + JSON.stringify(list.sort(setCondition({ position: 12 })), 0, 4) + '</pre>');
document.write('<pre>' + JSON.stringify(list.sort(setCondition({ worker: 'John' })), 0, 4) + '</pre>');
Excel VBA: Sort rows Numerically (by column value) THEN sort by one specific string

Excel VBA: Sort rows Numerically (by column value) THEN sort by one specific string


By : Amit
Date : March 29 2020, 07:55 AM
hope this fix your issue I don't know if this is the right approach for this. But here goes. I have some excel data: , Try this:
code :
ActiveSheet.Sort.SortFields.Clear
ActiveSheet.Sort.SortFields.Add Range("B1"), xlSortOnValues, xlAscending, "Open"
ActiveSheet.Sort.SortFields.Add Range("A1"), xlSortOnValues, xlDescending
With ActiveSheet.Sort
    .SetRange Range(Data)
    .Header = xlGuess
    .Orientation = xlTopToBottom
    .SortMethod = xlPinYin
    .Apply
End With
Dim SortStr As Variant
Dim SortNum As Long

'change below array as per your requirement
SortStr = Array("Open", "in progress", "almost finished")   
Application.AddCustomList ListArray:=SortStr
SortNum = Application.CustomListCount

ActiveSheet.Sort.SortFields.Clear
ActiveSheet.Sort.SortFields.Add Range("B1"), xlSortOnValues, xlAscending, SortNum
ActiveSheet.Sort.SortFields.Add Range("A1"), xlSortOnValues, xlDescending
With ActiveSheet.Sort
    .SetRange Range(Data)
    .Header = xlGuess
    .Orientation = xlTopToBottom
    .SortMethod = xlPinYin
    .Apply
End With

Application.DeleteCustomList Application.CustomListCount
C# Sort by boolean equality to static string, followed by sort on integer number ascending

C# Sort by boolean equality to static string, followed by sort on integer number ascending


By : Diana Serrano
Date : March 29 2020, 07:55 AM
This might help you Actually, I think OrderBy/ThenBy combo would work here:
var result = myList.OrderBy(d => d.Classifier == "Alpha").ThenBy(d => d.Code);
Related Posts Related Posts :
  • How do I make this image larger?
  • Run icCube with JDK 10
  • Expression with Math.random() always returns the same value
  • Getting the Set with the most elements nested in a HashMap using Java Streams
  • XmlSlurper to parse XML and get value of inside elements using Groovy
  • Extracting data from HTML and formatting the output
  • SOLR documentCache JMX metrics clarification
  • Limiting Wildfly 14 Two-Way SSL to specific clients
  • How do I get Min and max values to only print when "year" is entered?
  • Hashmap can't loop - getKey() method not found - Using Java 8
  • Android Studio - Create an EditText with a click of a button
  • Mockito Test not invoking verify() method
  • Wrap method implementations of Java interfaces
  • Remediating dynamic SQL into prepared statements
  • Where do X and Y start at in swing windows
  • java code with files work from eclipse but dont work from cmd
  • Return page object from JPA query
  • I can't figure out why this code in my APCS multiple choice book returns 19
  • How to save data between methods
  • I'm trying to install Apache Gobblin. How can I install it using Gradle?
  • Spring Data Sorting Array or Set into Pageable
  • Question about the Java documentation and its implementation
  • How to make a JButton that when pressed it does a new action
  • Java hibernate No validator could be found for boolean
  • Making a POJO Thread Safe
  • Save the data of a text file in a arraylist
  • Sort a List<String[]> by indices using Comparator
  • Overloading in Java for user input?
  • Unable to format timestamp as YYYY-MM-DD HH:mm:ss in java
  • Access SQLite Helper From Adapter
  • How to stream a csv file with header to a HashMap<String, Double> in Java?
  • can't get go daddy ssl certificate to work with spring boot
  • ResourceBundle can't find BaseName gradle project java
  • Java; Jackson; Parsing the array of array json string
  • Java - map key lookup ignoring case
  • Jackson deserialize map null values to empty string
  • Anyone knows why setCount() is not working in twitter4j?
  • Object Visibility in a Multi-threaded Program in Java
  • Can't store and load an arraylist in an object file
  • convert a string number starts with `00` to `+` in java
  • Java - avoiding NonSuchElementException using ConcurrentLinkedDeque
  • Converting Immutable to mutable list Java
  • Getting nosuchmethod exception
  • How to get MQTT subscriptions
  • Android Google Sign in Exceptions
  • JavaFX - method that waits for user input
  • Replacing values for a particular key in treemap changes values for every key
  • This method call passes a null value for a nonnull method parameter. Either the parameter is annotated as a parameter th
  • Kafka: consume all messages on demand
  • Notify what text was changed in textview
  • Tinkerpop/Gremlin: select vertices together with outgoing edge count
  • transform a list of objects into a list of integers that pass a check
  • Why this java code is showing strange behavior?
  • Maven Project classes not compiling
  • Edit image to make text more clear opencv
  • Android Spinner nullpointer
  • Add result to int array every time you finish counting the occurrence
  • Android import java library
  • How to use LDAP Authentication in a corporate environment
  • adding item during iteration in java special usecase
  • shadow
    Privacy Policy - Terms - Contact Us © bighow.org