compare

How to compare LocalDate instances Java 8

╄→尐↘猪︶ㄣ 提交于 2019-11-27 00:45:38
问题 I am writing an app that needs to be quite accurate in dates and I wonder how can I compare LocalDate instances.. for now I was using something like: LocalDate localdate1 = LocalDate().now(); LocalDate localdate2 = someService.getSomeDate(); localdate1.equals(localdate2); But I noticed that my app is giving me some confusing results, and I think it is because of the date comparing. I am thinking about obtaining the time from 1970' in long and compare those two, but I must be easier, I am sure

How to compare arrays in C#? [duplicate]

故事扮演 提交于 2019-11-27 00:43:19
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); You can use the Enumerable.SequenceEqual() in the System.Linq to compare the contents in the array bool isEqual = Enumerable.SequenceEqual(target1, target2); You're comparing the object references , and they are not the same. You need to compare the array contents. .NET2 solution An option is iterating through the array elements and call Equals() for each element. Remember that you

Text comparison algorithm

心不动则不痛 提交于 2019-11-27 00:33:19
We have a requirement in the project that we have to compare two texts (update1, update2) and come up with an algorithm to define how many words and how many sentences have changed. Are there any algorithms that I can use? I am not even looking for code. If I know the algorithm, I can code it in Java. Typically this is accomplished by finding the Longest Common Subsequence (commonly called the LCS problem). This is how tools like diff work. Of course, diff is a line-oriented tool, and it sounds like your needs are somewhat different. However, I'm assuming that you've already constructed some

Case insensitive comparison of strings in shell script

别来无恙 提交于 2019-11-27 00:03:57
The == operator is used to compare two strings in shell script. However, I want to compare two strings ignoring case, how can it be done? Is there any standard command for this? if you have bash str1="MATCH" str2="match" shopt -s nocasematch case "$str1" in $str2 ) echo "match";; *) echo "no match";; esac otherwise, you should tell us what shell you are using. alternative, using awk str1="MATCH" str2="match" awk -vs1="$str1" -vs2="$str2" 'BEGIN { if ( tolower(s1) == tolower(s2) ){ print "match" } }' alphaniner In Bash, you can use parameter expansion to modify a string to all lower-/upper-case

Comparing integer Arrays in Java. Why does not == work?

我的梦境 提交于 2019-11-26 23:23:00
问题 I'm learning Java and just came up with this subtle fact about the language: if I declare two integer Arrays with the same elements and compare them using == the result is false . Why does this happen? Should not the comparison evaluate to true ? public class Why { public static void main(String[] args) { int[] a = {1, 2, 3}; int[] b = {1, 2, 3}; System.out.println(a == b); } } Thanks in advance! 回答1: use Arrays.equals(arr1, arr2) method. == operator just checks if two references point to the

Compare multidimensional arrays in PHP

蹲街弑〆低调 提交于 2019-11-26 22:57:39
How can I compare multidimensional arrays in php? Is there a simple way? NullUserException The simplest way I know: $a == $b; Note that you can also use the === . The difference between them is: With Double equals == , order is important: $a = array(0 => 'a', 1 => 'b'); $b = array(1 => 'b', 0 => 'a'); var_dump($a == $b); // true var_dump($a === $b); // false With Triple equals === , types matter: $a = array(0, 1); $b = array('0', '1'); var_dump($a == $b); // true var_dump($a === $b); // false Reference: Array operators user151841 Another way to do it is to serialize() both of the arrays and

Compare files with awk

做~自己de王妃 提交于 2019-11-26 22:46:40
问题 Hi I have two similar files (both with 3 columns). I'd like to check if these two files contains the same elements (but listed in a different orders). First of all I'd like to compare only the 1st columns file1.txt "aba" 0 0 "abc" 0 1 "abd" 1 1 "xxx" 0 0 file2.txt "xyz" 0 0 "aba" 0 0 "xxx" 0 0 "abc" 1 1 How can I do it using awk? I tried to have a look around but I've found only complicate examples. What if I want to include also the other two columns on the comparison? The output should give

Compare two Images in JavaScript

点点圈 提交于 2019-11-26 22:41:51
问题 I am trying to determine if two images are the same in javascript (even if the src urls are different). My specific use case is within a chrome extension (though this being a chrome extension doesn't really factor into the question). I can get the imgage of a favicon png stored within chrome's internal database by setting the img src to: 'chrome://favicon/'+url where the url is the actual url of the website. However, I now want to find all the unique favicons. Given that they all will have a

Extract the difference between two strings in Java

ぃ、小莉子 提交于 2019-11-26 22:41:18
Hi I have two strings : String hear = "Hi My name is Deepak" + "\n" + "How are you ?" + "\n" + "\n" + "How is everyone"; String dear = "Hi My name is Deepak" + "\n" + "How are you ?" + "\n" + "Hey there \n" + "How is everyone"; I want to get what is not present in the hear string that is "Hey There \n". I found a method , but it fails for this case : static String strDiffChop(String s1, String s2) { if (s1.length() > s2.length()) { return s1.substring(s2.length() - 1); } else if (s2.length() > s1.length()) { return s2.substring(s1.length() - 1); } else { return ""; } } Can any one help ?

In Perl, is there a built in way to compare two arrays for equality?

我只是一个虾纸丫 提交于 2019-11-26 22:18:29
I have two arrays of strings that I would like to compare for equality: my @array1 = ("part1", "part2", "part3", "part4"); my @array2 = ("part1", "PART2", "part3", "part4"); Is there a built-in way to compare arrays like there is for scalars? I tried: if (@array1 == @array2) {...} but it just evaluated each array in scalar context, and so compared the length of each array. I can roll my own function to do it, but it seems like such a low-level operation that there should be a built-in way to do it. Is there? Edit: sadly, I don't have access to 5.10+ or optional components. Sinan Ünür There is