comparator Questions
2
Solved
I know that it makes perfect sense to define e.g. move constructor as noexcept (if possible) and I think I understand the effect of that.
But I have never seen a similar discussion about operator&l...
Massingill asked 10/7, 2024 at 11:44
2
Below is a block of code that results in exception as indicated,
Code :
Collections.sort( arrayList, new Comparator()
{
public int compare( Object o1, Object o2 )
{
TypeAdapterSort tas1 = ( T...
Arrangement asked 18/4, 2013 at 8:58
15
Solved
Can someone explain me in simple terms, why does this code throw an exception, "Comparison method violates its general contract!", and how do I fix it?
private int compareParents(Foo s1, Foo s2) {...
Unbolt asked 30/11, 2011 at 14:31
14
Solved
Is there any difference between:
SELECT * FROM users WHERE username="davyjones"
and
SELECT * FROM users WHERE username LIKE "davyjones"
Bearden asked 1/10, 2009 at 16:25
4
Solved
I need to compare time zones such that Asia/Singapore < UTC < Pacific/Honolulu.
I'm working with java.util.TimeZone (which doesn't implement Comparable).
My search for an existing implementat...
Yahweh asked 2/3, 2013 at 0:19
2
Solved
I have a Map with an enumeration type as the key and Double as the value. I want to sort this based on the Double values. So I got the entry set and want to use Collections.sort() with a comparator...
Athapaskan asked 20/6, 2013 at 10:28
2
Solved
Is there a build-in possibility to create a null-safe mapping comparator in Java 8 without writing a own implementation of Comparator?
When running the following code, it causes a NPE because the ...
Evannia asked 13/2, 2015 at 12:40
3
Solved
I have an object which has a name and a score. I want to sort the elements by name and find the max score for that name.
For example below are the objects (name, score):
(a, 3)
(a, 9)
(b, 7)
(b, ...
Pupa asked 19/6, 2019 at 12:6
2
Solved
I am using C++17.
std::set is a template type:
template<
class Key,
class Compare = std::less<Key>,
class Allocator = std::allocator<Key>
> class set;
One can have a std::set ...
Carving asked 19/1, 2023 at 7:40
15
Solved
Im trying to sort through an arraylist of objects by a particular value within the object. What would be the best approach to do such a thing. Should I use Collections.sort() with some kind of comp...
Tortuga asked 2/2, 2012 at 9:29
13
Solved
I saw many questions about this, and tried to solve the problem, but after one hour of googling and a lots of trial & error, I still can't fix it. I hope some of you catch the problem.
This is...
Sunken asked 11/7, 2012 at 21:20
6
Solved
I have an ArrayList and want sort it in descending order. I use for it java.util.stream.Stream.sorted(Comparator) method. Here is a description according Java API:
Returns a stream consisting of...
Prince asked 7/10, 2015 at 14:53
6
I have the following list of double values:
items {9.0, 4.0, 16.0, -6.0, 5.0}
I want to find the maximum and minimum values and for that I did:
double max = items.stream().max(Comparator.compar...
Temptation asked 7/8, 2018 at 13:41
3
Solved
Consider the following example where we are sorting people based on their last name:
public class ComparatorsExample {
public static class Person {
private String lastName;
public Person(Stri...
Alembic asked 8/5, 2020 at 14:43
2
Solved
Let's say I am building a TreeSet of an object for which the ordering depends on only one value.
I cannot do
TreeSet<Foo> tree = new TreeSet<>(Comparator.comparingInt(Foo::getX));
beca...
Kaylakayle asked 2/10, 2022 at 11:44
5
Solved
So I'm working with a few pre-existing comparators that compare certain values in two tuples and return true if the first is greater than the second, false if otherwise. Here's the code for one of ...
Varicocele asked 5/10, 2012 at 15:26
4
Solved
I understand in
Comparator < ? super T> comp
it returns the maximum element of the given collection, according to the order defined by the specified comparator. But I don't understand the pu...
Feaze asked 9/12, 2012 at 9:37
8
Solved
How does the following code sort this array to be in numerical order?
var array=[25, 8, 7, 41]
array.sort(function(a,b){
return a - b
})
I know that if the result of the computation is...
L...
Maneating asked 29/9, 2009 at 20:21
4
Solved
Suppose I have a domain model like this:
class Lecture {
Course course;
... // getters
}
class Course {
Teacher teacher;
int studentSize;
... // getters
}
class Teacher {
int age;
... // ...
Bream asked 22/7, 2016 at 18:42
4
Solved
As far as I understand Comparator is a functional interface used to compare 2 objects with int compare(T o1, T o2) as the abstract function that takes two argument.
but there is also a function Com...
Copperhead asked 20/3, 2022 at 16:10
2
Solved
I know from official documentation that compareBy
creates a comparator using the sequence of functions to calculate a result of comparison. The functions are called sequentially, receive the given ...
Mas asked 10/3, 2022 at 7:9
2
Solved
I have a list of points where each point is a tiny list of size 2. I want to sort the list of points in increasing order of x and if x values are equal, I break tie by sorting in decreasing order o...
Pointsman asked 5/3, 2022 at 15:3
2
Solved
I want to sort seq1 ascending and seq2 descending so I do this:
list = list.stream().sorted(comparing(AClass::getSeq1).thenComparing(
AClass::getSeq2).reversed()).collect(toList());
But the re...
Mojave asked 21/5, 2015 at 19:14
5
Solved
Say, we have the following 2-dimensional array:
int camels[][] = new int[n][2];
How should Java Comparator class be declared to sort the arrays by their first elements in decreasing order using ...
Trituration asked 22/3, 2011 at 15:2
10
Solved
We have some code which sorts a list of addresses based on the distance between their coordinates. this is done through collections.sort with a custom comparator.
However from time to time an addre...
Wildfire asked 8/3, 2010 at 13:35
1 Next >
© 2022 - 2025 — McMap. All rights reserved.