python (65.1k questions)
javascript (44.2k questions)
reactjs (22.7k questions)
java (20.8k questions)
c# (17.4k questions)
html (16.3k questions)
r (13.7k questions)
android (12.9k questions)
How to sort an ArrayList of ArrayLists (by one of the variables) in Java?
(Java 8) I have an ArrayList of ArrayLists as follows:
[5, 10]
[2, 11]
[1, 12]
[8, 13]
I want these lists to be sorted by the first value in the list in either ascending or descending order. For examp...
regamblr
Votes: 0
Answers: 1
Why do I need to typecast when using thenComparing in Java
I'm deeply confused by why the first block of code can compile, while the second block of code can't compile.
Can compile
int[][] arr = {{2,2}, {1,2}, {3,4}};
List<int[]> list = ...
rigby
Votes: 0
Answers: 1
C++ Finding minimum in vector of structs using custom comparator
I have a vector of structs:
struct element_t {
int val;
bool visited;
};
With a custom comparator:
bool cmp(const element_t& lhs, const element_t& rhs)
{
return ((lhs.val < rhs...
Vojtooo
Votes: 0
Answers: 3
How to apply comparator to get the TOP 5 cities from a List sorted by population?
I have a class City
public final class City {
private final String name;
private final String state;
private final int population;
public City(String name, String state, int population) {
this...
John Smith
Votes: 0
Answers: 4