Questions tagged [comparison]

Questions about data comparison and efficient ways to accomplish it. Please avoid using this tag for generic (meta) comparison of two issues or concepts.

Questions about data comparison and efficient ways to accomplish it, e.g.: "Which is the fastest algorithm to compare two recordsets and decide which one has more palindromes?", or "What is the fastest way to compare two strings and say if they have more than Y characters in common?"

There are generally six basic "comparison operators": less than, <; less than or equal to, <=; equal to, ==; not equal to, !=; greater than or equal to, >=; and greater than, >.

8118 questions
122
votes
14 answers

Comparing two .jar files

How do I compare two .jar files? Both of them have compiled .class files. I want the difference in terms of method changes, etc.
Kunal
  • 2,929
  • 6
  • 21
  • 23
122
votes
6 answers

MySQL compare DATE string with string from DATETIME field

I have a question: Is it possible to select from a MySQL database by comparing one DATE string "2010-04-29" against strings that are stored as DATETIME (2010-04-29 10:00)? I have one date picker that filters data and I would like to query the table…
Manny Calavera
  • 6,815
  • 20
  • 60
  • 85
122
votes
5 answers

What’s the difference between ScalaTest and Scala Specs unit test frameworks?

Both are BDD (Behavior Driven Development) capable unit test frameworks for Scala written in Scala. And Specs is built upon may also involve the ScalaTest framework. But what does Specs offer ScalaTest doesn't? What are the differences?
Alex
  • 8,245
  • 8
  • 46
  • 55
121
votes
3 answers

Is it safe to assume strict comparison in a JavaScript switch statement?

I have a variable that can either be boolean false, or an integer (including 0). I want to put it in a switch statement like: switch(my_var){ case 0: // Do something break; case 1: // Do something else …
Paul
  • 139,544
  • 27
  • 275
  • 264
120
votes
5 answers

Compare dates in MySQL

I want to compare a date from a database that is between 2 given dates. The column from the database is DATETIME, and I want to compare it only to the date format, not the datetime format. SELECT * FROM `players` WHERE…
NVG
  • 3,248
  • 10
  • 40
  • 60
120
votes
3 answers

Why does this string extension method not throw an exception?

I've got a C# string extension method that should return an IEnumerable of all the indexes of a substring within a string. It works perfectly for its intended purpose and the expected results are returned (as proven by one of my tests, although…
ArtOfCode
  • 5,702
  • 5
  • 37
  • 56
120
votes
4 answers

LINQ Distinct operator, ignore case?

Given the following simple example: List list = new List() { "One", "Two", "Three", "three", "Four", "Five" }; CaseInsensitiveComparer ignoreCaseComparer = new CaseInsensitiveComparer(); var distinctList =…
Ash
  • 60,973
  • 31
  • 151
  • 169
120
votes
3 answers

Type-juggling and (strict) greater/lesser-than comparisons in PHP

PHP is famous for its type-juggling. I must admit it puzzles me, and I'm having a hard time to find out basic logical/fundamental things in comparisons. For example: If $a > $b is true and $b > $c is true, must it mean that $a > $c is always true…
hakre
  • 193,403
  • 52
  • 435
  • 836
118
votes
12 answers

How do I make my string comparison case-insensitive?

I created a Java program to compare two strings: String str = "Hello"; if (str.equals("hello")) { System.out.println("match"); } else { System.out.println("no match"); } It's case-sensitive. How can I change it so that it's not?
user268018
  • 1,245
  • 2
  • 9
  • 7
117
votes
11 answers

Java Compare Two Lists

I have two lists ( not java lists, you can say two columns) For example **List 1** **Lists 2** milan hafil dingo iga iga dingo elpha binga hafil …
user238384
  • 2,396
  • 10
  • 35
  • 36
116
votes
4 answers

Comparing boxed Long values 127 and 128

I want to compare two Long objects values using if conditions. When these values are less than 128, the if condition works properly, but when they are greater than or equal to 128, comparison fails. Example: Long num1 = 127; Long num2 = 127; if…
Viraj Dhamal
  • 5,165
  • 10
  • 32
  • 41
115
votes
18 answers

Comparing Arrays of Objects in JavaScript

I want to compare 2 arrays of objects in JavaScript code. The objects have 8 total properties, but each object will not have a value for each, and the arrays are never going to be any larger than 8 items each, so maybe the brute force method of…
AdamB
  • 8,850
  • 5
  • 22
  • 14
113
votes
10 answers

How to check if a string starts with another string in C?

Is there something like startsWith(str_a, str_b) in the standard C library? It should take pointers to two strings that end with nullbytes, and tell me whether the first one also appears completely at the beginning of the second…
thejh
  • 44,854
  • 16
  • 96
  • 107
113
votes
7 answers

What is the proper way to check if a string is empty in Perl?

I have been using this code to check if a string is empty: if ($str == "") { // ... } And also the opposite with the not equals operator... if ($str != "") { // ... } This seems to work (I think), but I'm not sure it's the correct way, or if…
Nick Bolton
  • 38,276
  • 70
  • 174
  • 242
111
votes
22 answers

How to check if an integer is in a given range?

Hoping for something more elegant than if (i>0 && i<100)
herpderp
  • 15,819
  • 12
  • 42
  • 45