Skip to main content
Filter by
Sorted by
Tagged with
5 votes
0 answers
148 views

Background: I'm debugging a Java sorting setup where I found a faulty Comparator already (violates the contract). My goal is to implement a test case which provokes the well-known java.lang....
polo's user avatar
  • 57
0 votes
0 answers
118 views

I am implementing an ordered list that automatically inserts elements in the correct sorted position using a Comparator. The list is built from scratch (not using java.util.ArrayList) and uses an ...
Raam's user avatar
  • 11
2 votes
1 answer
67 views

I need to sort the column with "File creation date", but if the column "File type" == FyleType.DIRECTORY this row should be at the top. That is, first sorting should be by type, ...
Starkvell's user avatar
1 vote
2 answers
107 views

I am trying to sort the tuples in the 2D array based on a single column value similar to Javascript's sort function. arr.sort((a,b) => a[0] - b[0]) C Code : #include<stdio.h> #...
Bittu970's user avatar
  • 107
-1 votes
3 answers
138 views

I have a few compare method in a class and im not sure which way i should do them First option i came up public static Comparator<Student> nameCompare(String str) { if (str.equals("ASC&...
Joseph Jones's user avatar
0 votes
0 answers
62 views

I'm being asked to create a binary search that can use either Comparable or Comparator depending on which constructor is being used. I made a private boolean to note whether or not to use the object's ...
Drake's user avatar
  • 19
-2 votes
1 answer
168 views

In Java, how come that the comparators will take the values in pairs when we define the logic like this? Integer[] arr = { 1, 2, 3, 4 }; Arrays.sort(arr, (a, b) -> { return a - b; }); How does it ...
Naveen B S's user avatar
4 votes
3 answers
266 views

In the case where we have a class with a lot of fields - let's say for example a BankAccount class: class BankAccount implements Comparable<BankAccount> { Double amount; String name; ...
Lyee's user avatar
  • 41
1 vote
2 answers
114 views

I need some help with an issue I'm facing when comparing two lists of objects (TestFoo type). The goal is to check both list is equals or not The Goal: I need to compare existingItems and newItems (...
Anandharaj Anandharaj's user avatar
0 votes
2 answers
95 views

I have a DTO class class MyDto { private String f1; private String f2; private String f3; // constructor // get set equals/hashCode } It has equal/hascode pair which takes into ...
gstackoverflow's user avatar
0 votes
0 answers
36 views

Even after reading documentations and multiple posts about this error I still don't understand the following case: This line will generate the error Non-static method cannot be referenced from a ...
Linda Martin's user avatar
0 votes
0 answers
34 views

So, I'm kind of new to Java, and I was trying to test the reversed method ( in Comparator functional interface), and tried it in two different approaches. One with using it after defining a lambda ...
user avatar
1 vote
1 answer
103 views

I have a java class.. public class response_message { private String message; private String rejectCode; private int ruleSeqNo; private String contInd; public String getMessage() ...
Johnson Francis's user avatar
1 vote
3 answers
144 views

Sorting a list of integers except negative numbers in java , negative numbers indexes should remain same I tried to achieve above condition using a custom comparator but it fails list.sort((a,b)->(...
Arjun's user avatar
  • 1,262
0 votes
1 answer
80 views

Say I'm implementing a sorted set in Java with a generic <T>, like a binary search tree. The set uses a Comparator<T> to order its elements. For simplicity, let's assume the comparator is ...
Stephen Ware's user avatar
3 votes
1 answer
110 views

Say I have a Person class like this. class Person { friend std::ostream &operator<<(std::ostream &out, const Person &operand); public: Person(std::string name, std::string ...
VivekDev's user avatar
  • 26.1k
3 votes
1 answer
96 views

Context: Modern java (the latest version; JDK23 at time of writing this question) Given 2 objects that are comparable (implement Comparable<T>, where T is a type they all share), how does one ...
rzwitserloot's user avatar
7 votes
2 answers
215 views

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<()...
Jarek C's user avatar
  • 1,281
0 votes
2 answers
82 views

I'm a beginner in Kotlin and I'm trying to learn about comparison so i wrote this code: fun main() { val laptops = listOf( laptop(2020, 8, 1000), laptop(2022, 4, 800), ...
Fatima Bourouba's user avatar
0 votes
1 answer
76 views

The below is the Employee class which has a public static nested class called EmployeeNameComparator . import java.util.Comparator; public class Employee { public static class ...
Shermukhammad Karimov's user avatar
1 vote
1 answer
225 views

I am not very familiar with C++, and am confused about how a comparator works. The below code is how I can find the position I want to insert a new interval: #include <algorithm> #include <...
Yuan's user avatar
  • 51
0 votes
2 answers
47 views

Please I hope someone can help, I think is easy, but I am having problems to find the correct way for this online. I need to know changes in QTY to get a report to know what moves what does not. 1- ...
Dany's user avatar
  • 1
2 votes
1 answer
101 views

We can apply comparable & comparator both on integers, as like below: List<Integer> intList1 = Arrays.asList(1,9,4,8,2,3,7,4,5); Optional<Integer> val1 = intList1.stream().sorted((a, b)...
Ajit A Ankalle's user avatar
0 votes
1 answer
178 views

I have a what seems to be a simple but odd finding. When I use: WHERE DateTime >= '2024-04-01' AND DateTime <= '2024-04-30' This above only gives me up to 04/29, but not 04/30 WHERE DateTime &...
Ryan's user avatar
  • 11
0 votes
1 answer
58 views

I have a Dictionary with keys of type Setting, where setting is a struct with members mCategory (String), mIndex (int), and mDescription (String). Some of the keys are unique - there will be at most ...
Arannya Monzur's user avatar
0 votes
1 answer
137 views

Writing a macro for data output and I need to compare cell addresses to ensure the macro is pulling data from the correct block of data. Code Example: Dim SectionSTART As Variant SectionSTART = ...
J. Hartsuyker's user avatar
2 votes
4 answers
129 views

According to the docs, thenComparing default <U extends Comparable<? super U>> Comparator thenComparing(Function<? super T,? extends U> keyExtractor) Returns a lexicographic-order ...
CocoaNut's user avatar
0 votes
4 answers
465 views

Suppose I have an array of [0,7,4,0,0,8,3,0,0,0,5,6] and I have to take all the zeroes to last positions after other numbers without modifying their order. So the output array should be like : [7,4,8,...
Girija Dash's user avatar
0 votes
1 answer
38 views

I am trying to sort a list of tuples on the lexicographic order of the sub-string that the tuples are indicating. In the following case, I wish to sort a which actaully represents ["sd", &...
Grandmarkkk's user avatar
1 vote
1 answer
119 views

#include <set> #include <string> #include <unordered_map> #include <vector> int main() { std::vector<std::string> wordsContainer={"aba", "baba",&...
cheems's user avatar
  • 224
-1 votes
1 answer
66 views

I want to compare StudentDTO class object. StudentDTO s1 = new StudentDTO(); StudentDTO s2 = new StudentDTO(); s1.equals(s2) I have Class StudentDTO contains AddressDTO class object as ...
user2042166's user avatar
0 votes
1 answer
230 views

I have a TreeMap full of Houses. Each house has different properties such as address, number of floors, etc. The TreeMap gets populated into a JList so that the user can select a house from the list, ...
chalcedony's user avatar
-1 votes
1 answer
105 views

Product with fields (id, productName, categoryName, etc).After making Arraylist of product and Populating it with Values like ArrayList<Product> products = new ArrayList<Product>(Arrays....
Jaykumar's user avatar
  • 443
-1 votes
1 answer
106 views

I have a problem using lower_bound to find element in array by 2 parameters. I have a struct person{ public: person(const std::string CITY, const std::string ADDRESS, const std::string REGION, ...
Ilya Chaban's user avatar
1 vote
1 answer
60 views

The following code return Nullpointer exception: Comparator<LocalDate> c = (LocalDate d1,LocalDate d2)-> {return (d1.isAfter(d2) ? 1 : (d1.isBefore(d2)? -1: 0));} ; List<LocalDate> ...
rjs's user avatar
  • 23
1 vote
2 answers
381 views

I know there are many similar questions about the same issue. However, I've tried the solutions provided and none worked for me. I am 100% sure it is something basic I am missing, but I am not able to ...
xerez's user avatar
  • 89
0 votes
0 answers
203 views

I'm encountering an issue with the STM32 internal comparator (COMP). Although the signal comparison works as expected, I've observed that enabling the COMP causes a significant increase in current ...
Ubaid Ullah's user avatar
-1 votes
2 answers
89 views

I have the below method for custom code to Sort and the requirement is that we have to do the custom sort based on BoardPoint, OffPoint, LastName, and FirstName. Sort first based on BoardPoint If ...
ashish gupta's user avatar
-2 votes
1 answer
99 views

I need to find the Students ranks based on the subjectPriorityOrder given. Student list contains subject list with marks. Subject Priority Order list has the priority order which one we should have to ...
Rudra's user avatar
  • 1
2 votes
1 answer
184 views

My problem arises from DevExpress TcxGrid default comparison (used for the sorting of data), which boils down to the code (implemented in cxVariants.pas): if VarIsEmpty(V1) then if VarIsEmpty(V2)...
TomR's user avatar
  • 3,364
0 votes
1 answer
56 views

Lets say there are two lists: List<Integer> listA = Arrays.asList(1,2,3,4,5,6,7,6,5,4,3,2,1,0); This list is a template for sorting another listB. List<Integer> listB = Arrays.asList(0,106,...
Kapil Panchal's user avatar
0 votes
1 answer
117 views

Consider the following Java example: int[] a = new int[]{1, 2}; PriorityQueue<Integer> pq = new PriorityQueue<Integer>(Comparator.comparingInt(i -> a[i])); pq.add(0); pq.add(1); a[1] = ...
Dmitry's user avatar
  • 340
0 votes
1 answer
436 views

I am trying to do a sorting of some number. I am getting a "java.lang.IllegalArgumentException: Comparison method violates its general contract!" Exception when I execute the following code. ...
jos.mathew123's user avatar
0 votes
1 answer
160 views

I use Java 17. Here is my code: public static class SortByPercentLike implements VideoSorterInterface { // define Lambda Function Comparator<Video> videoPercentLikeComparator ...
OzanCinci's user avatar
2 votes
1 answer
142 views

I am printing video tracks to user in "height" + "p" format. By default TrackSelectionDialog printing them let's say in random order. I want to reorder them from min to max. So I ...
danyapd's user avatar
  • 2,506
0 votes
1 answer
76 views

I have a class Range and a comparator in Java: class Range{ int start; int end; } class RangeComparator implements Comparator<Range> { @Override public int compare(Range range1, ...
leo's user avatar
  • 437
-2 votes
2 answers
105 views

MRE because well, assignment... sigh This is the problem I'm stuck on: Consider the following class: class MyClass<T extends Comparable<T>> implements Comparable<MyClass<T>> { ...
kesarling's user avatar
  • 2,318
0 votes
1 answer
85 views

So I have this class where I'm trying to initialize a SortedMap using a Comparator I created in another class (separate files) Why is this part not working? Comparator<Map.Entry<Country, Pair<...
Docas 95's user avatar
2 votes
5 answers
1k views

How do I return the most recent date after comparing all the elements in the Array List? The expectation is to return 2023-01-03T02:00:00.800Z value as it is the most recent date in the list out of ...
krsna's user avatar
  • 4,343
0 votes
1 answer
379 views

I am trying to sort Car by three values: first by type, then within the "type" bucket I want to sort those by price (lowest to highest), then if there are any that have the same price, I ...
N.A's user avatar
  • 311

1
2 3 4 5
57