Java 8 Lambda: Comparison

I want to sort a list with Lambda: List<Message> messagesByDeviceType = new ArrayList<Message>(); messagesByDeviceType.sort((Message o1, Message o2)->o1.getTime()-o2.getTime()); But I got this compilation error: Multiple markers at this lin

Sorting a list of string arrays

I am receiving a list of String array String[] sa1 = {"120", "John" , "30" , "[\"science\",\"arts\"]"}; String[] sa2 = {"20", "Michael" , "29" , "[\"commer

Error with two pieces of code almost identical

**I am new to C so please keep that in mind when answering I'm currently working on a larger program where I use classes called integer.c (which defines an integer and functions used on it), real.c (which defines a double and functions used on it) an

Java Override CompareTo Method

I have Coordinates class and I want to make Coordinates object comparable. public class Coordinates implements Comparable<Coordinates> { private int row; private int column; The idea is to insert Coordinates objects into PriorityQueue and to get the

Sorting a table based on an iOS comparison model

Student *s1 = [Student new]; s1.city = @"Delhi"; Student *s2 = [Student new]; s2.city = @"Mumbai"; NSArray *arrModels = @[s1,s2]; NSArray *arrCompareModel = @[@"Mumbai",@"Delhi"]; I need to sort the arrModels based

ImmutableSortedMap - Duplicate Keys in Mappings

I have an ImmutableSortedMap that holds data in the following datastructure. <String, Pair<Long, Double>> My goal is to sort this map in descending order starting with the largest Double and if two Doubles are the same, sort it by the Long. If

Is it the dynamic comparator & quot; available in C ++

I am looking for a "dynamic comparator" that gives comparison result depending on a run-time argument. Here is a comparator that compares two integers according to their distances to an input argument x. struct leq { bool operator()(const int a,

Sort a list based on the index of another list of values

I am trying to use a comparator to sort my List 2 based on List 1. So the two lists are: ListA = [2,3,4] ListB = [8,2,4] I need to sort list 2 based on list 1. Expected output: List1: [2,3,4] List2: [2,8,4] Here is the code I am trying Collections.so

Sort the double table in a specific order

I am trying to sort an array to specific order, for an example: I want to sort the array map as [2, 0, 1, 2] according to the order or arr. But I am getting errors. double[] arr = {3, 1.3, 2, 3}; int[] map = {0, 1, 2, 3}; // I want to get [2, 0, 1, 2

Can not sort null with comparator

This question already has an answer here: What is a NullPointerException, and how do I fix it? 12 answers I keep getting a nullpointerexception when I try to sort users where a certain user has a null value in his profile. I was under the impression

List & lt; List & lt; Object & gt; & gt; sorting

I am facing an issue while sorting List<List<Object>>. I have created a Custom Comparator where i have written the code to sort the data. public class CustomComparator implements Comparator<List<Object>> { static int i = 0; public

Linq of full outer join using union [SOLVED]

I have two lists var left={[ID=1,Name='A',Qty1=0,Qty2=5],[ID=2,Name=B,Qty1=0,Qty2=52]}; var right={[ID=1,Name='A',Qty1=57,Qty2=0],[ID=2,Name=B,Qty1=84,Qty2=0]}; var outer=left.union(right); I want to get the following result: outer={[ID=1,Name='A',Qt

Do not implement all methods of an interface

I tried reproducing the code below on eclipse. I get an error telling me that I have to implement all the inherited methods (because Comparator is an interface). The type new Comparator(){} must implement the inherited abstract method Comparator.reve

Problem with Sorting ArrayList using the collection

I am trying to sort VariantOptionData ArrayList using its one of parameter. here is my VariantOptionData public class VariantOptionData implements java.io.Serializable { private Collection<VariantOptionQualifierData> variantOptionQualifiers; private

Double comparator does not work

I have developed a program that creates an array of Book Objects and sorts them based on user input. The sorting options are author-title-pages-price, and all work but the price sort. Please help me find why I cannot sort doubles using Comparator...

sort a list of objects based on the runtime property

I have an arraylist of VOs. These objects have many properties and corresponding get/set methods. I want to sort this array list based on a property which I'll be getting in runtime. Let me explain in detail. My VO is like this public class Employee

read the text file and store it in hashmap. Then sort in order

File is like this: name1 134.2 name2 456.7 name3 265.3 ... ... I read the text file and store in HashMap after that I want to sort in order(by the highest value) but the problem is that because I sort the values in String, I cant compare it. So..is t

Sorting a table using the comparator

I have the following code. When I try to compile it, it gives me the following error: The method sort(List<T>, Comparator<? super T>) in the type Collections is not applicable for the arguments (Software[], new Comparator(){}) The type new Com

java object comparison list

I am having List<Student> stud1 = new ArrayList<Student>(); and List<Student> stud2 = new ArrayList<Student>(); And Student class is having members like name, address. What i have to do is , I have to list the Student from stud1 (i

Comparator implementation several times in a single class file

This question already has an answer here: How do I make 2 comparable methods in only one class? 3 answers I have some code to sort paths by date modified. I want to also write some code to sort the paths in reverse order, and might later want to add

OCaml: Using a comparison operator passed in a function

I'm an OCaml noob. I'm trying to figure out how to handle a comparison operator that's passed into a function. My function just tries to pass in a comparison operator (=, <, >, etc.) and an int. let myFunction comparison x = if (x (comparison) 10) t

How to sort a collection by a date field?

I'm trying to sort an album by release date. For some reason I am not getting anywhere: //sort by release date Collections.sort(this._items, new Comparator<Album>() { public int compare(Album t1, Album t2) { int dateCmp = t2.getStartDate().compareTo

How to get list of Set and Comparator

What is the "good" (and why ?) solution to get a List from a Set and sorted against a given Comparator ? Set<Object> set = new HashSet<Object>(); // add stuff List<Object> list = new ArrayList<Object>(set); Collections.so

Java comparator for simple custom logic

How I can find line 4,1 and 6 in example below? And is the use of Collection.sort() with Comparator reasonable in this case? a - b - c - d 1.) 6 8 16 18 2.) 38 40 55 57 3.) 6 8 25 27 4.) 1 5 11 15 5.) 6 8 3 5 6.) 9 12 19 22 7.) 18 20 1 3 8.) 23 25 15