Questions tagged [compare]

The analysis required to assess the differences and similarities between two or more entities.

This tag is used to classify a question as one dealing with the comparison of at least two entities. The essence of questions that are tagged should boil down to one of the following questions:

  1. How do I control when the compiler/interpreter thinks that two entities are equal? How do I control when the compiler/interpreter thinks that two entities are unequal?
  2. How do I control when the compiler/interpreter thinks that one entity is bigger than the other?
  3. How do I control when the compiler/interpreter thinks that one entity is smaller than the other?

Note that in some languages, it is possible to define asymmetric inequalities. That is, cases in which a<b does not mean that b<a. This is why in python, there exist separate functions for __gt__ (greater than) and __lt__ (less than), etc

10212 questions
195
votes
6 answers

Tool for comparing 2 binary files in Windows

I need a tool to compare 2 binaries. The files are quite large. Some freeware or trial tools I found on the Internet are not convenient to use for large files. Can you recommend me some tools?
mustafa
  • 3,605
  • 7
  • 34
  • 56
187
votes
32 answers

How to know if two arrays have the same values

I have these two arrays: one is filled with information from an ajax request and another stores the buttons the user clicks on. I use this code (I filled with sample numbers): var array1 = [2, 4]; var array2 = [4, 2]; //It cames from the user button…
Carlos Precioso
  • 2,731
  • 3
  • 21
  • 24
182
votes
9 answers

What is the difference between == and Equals() for primitives in C#?

Consider this code: int age = 25; short newAge = 25; Console.WriteLine(age == newAge);  //true Console.WriteLine(newAge.Equals(age)); //false Console.ReadLine(); Both int and short are primitive types, but a comparison with == returns true and a…
Mohammad Zargarani
  • 1,422
  • 2
  • 12
  • 19
166
votes
7 answers

Compare version numbers without using split function

How do I compare version numbers? For instance: x = 1.23.56.1487.5 y = 1.24.55.487.2
Sankar M
  • 4,549
  • 12
  • 37
  • 55
163
votes
17 answers

Compare JavaScript Array of Objects to Get Min / Max

I have an array of objects and I want to compare those objects on a specific object property. Here's my array: var myArray = [ {"ID": 1, "Cost": 200}, {"ID": 2, "Cost": 1000}, {"ID": 3, "Cost": 50}, {"ID": 4, "Cost": 500} ] I'd like…
firedrawndagger
  • 3,573
  • 10
  • 34
  • 51
160
votes
3 answers

How to compare two files not in repo using git

I'd like to compare two css files which are not in any git repository. Is there such a functionality in git?
Cedric Reichenbach
  • 8,970
  • 6
  • 54
  • 89
159
votes
13 answers

How can I compare two dates in PHP?

How can I compare two dates in PHP? The date is stored in the database in the following format 2011-10-2 If I wanted to compare today's date against the date in the database to see which one is greater, how would I do it? I tried this, $today =…
Exploit
  • 6,278
  • 19
  • 70
  • 103
157
votes
5 answers

java.util.Objects.isNull vs object == null

As you know, java.util.Objects is This class consists of static utility methods for operating on objects. One of such methods is Objects.isNull(). My understanding is that Objects.isNull() would remove the chance of accidentally assigning a null…
Lucas T
  • 3,011
  • 6
  • 29
  • 36
156
votes
21 answers

How to compare 2 files fast using .NET?

Typical approaches recommend reading the binary via FileStream and comparing it byte-by-byte. Would a checksum comparison such as CRC be faster? Are there any .NET libraries that can generate a checksum for a file?
Robin Rodricks
  • 110,798
  • 141
  • 398
  • 607
154
votes
4 answers

MongoDb query condition on comparing 2 fields

I have a collection T, with 2 fields: Grade1 and Grade2, and I want to select those with condition Grade1 > Grade2, how can I get a query like in MySQL? Select * from T Where Grade1 > Grade2
Diego Cheng
  • 1,793
  • 3
  • 12
  • 7
136
votes
5 answers

Find oldest/youngest datetime object in a list

I've got a list of datetime objects, and I want to find the oldest or youngest one. Some of these dates might be in the future. from datetime import datetime datetime_list = [ datetime(2009, 10, 12, 10, 10), datetime(2010, 10, 12, 10, 10), …
panosl
  • 1,709
  • 2
  • 12
  • 15
135
votes
6 answers

How to compare arrays in C#?

Possible Duplicate: Easiest way to compare arrays in C# How can I compare two arrays in C#? I use the following code, but its result is false. I was expecting it to be true. Array.Equals(childe1,grandFatherNode);
mahdi
  • 16,257
  • 15
  • 52
  • 73
121
votes
13 answers

Java error: Comparison method violates its general contract

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 what I get: java.lang.IllegalArgumentException:…
Lakatos Gyula
  • 3,949
  • 7
  • 35
  • 56
110
votes
11 answers

Query comparing dates in SQL

I have a table with dates that all happened in the month November. I wrote this query select id,numbers_from,created_date,amount_numbers,SMS_text from Test_Table where created_date <= '2013-04-12' This query should return everything that…
HelpASisterOut
  • 3,085
  • 16
  • 45
  • 89
109
votes
13 answers

Checking for duplicate strings in JavaScript array

I have JS array with strings, for example: var strArray = [ "q", "w", "w", "e", "i", "u", "r"]; I need to compare for duplicate strings inside array, and if duplicate string exists, there should be alert box pointing to that string. I was trying to…
Bengall
  • 1,267
  • 2
  • 9
  • 13