compare

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

做~自己de王妃 提交于 2019-11-28 00:14:37
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! use Arrays.equals(arr1, arr2 ) method. == operator just checks if two references point to the same object. Test: int[] a = {1, 2, 3}; int[] b = a; System.out.println(a == b); //returns true as b and a

Comparing strings lexicographically

眉间皱痕 提交于 2019-11-27 23:32:15
I thought that if I used operators such as ">" and "<" in c++ to compare strings, these would compare them lexicographically, the problem is that this only works sometimes in my computer. For example if("aa" > "bz") cout<<"Yes"; This will print nothing, and thats what I need, but If I type if("aa" > "bzaa") cout<<"Yes"; This will print "Yes", why is this happening? Or is there some other way I should use to compare strings lexicographically? Comparing std::string -s like that will work. However you are comparing string literals. To do the comparison you want either initialize a std::string

When you call remove(object o) on an arraylist, how does it compare objects?

泪湿孤枕 提交于 2019-11-27 23:27:01
When you call remove(object o) on an arraylist in java, how does it compare the objects to find the correct one to remove? does it use the pointer? or does it compare the objects using the interface Comparable? Eric ArrayList remove() relies on the objects implementation of the Equal method. If no implementation has been done then the object is removed by Object 's implementation of Equals which indeed is the pointer comparison. From the documentation on ArrayList - More formally, removes the element with the lowest index i such that (o==null ? get(i)==null : o.equals(get(i))) (if such an

NSString - how to go from “ÁlgeBra” to “Algebra”

让人想犯罪 __ 提交于 2019-11-27 22:45:59
Does anyone knows hoe to get a NSString like "ÁlgeBra" to "Algebra", without the accent, and capitalize only the first letter? Thanks, RL NSString has a method called capitalizedString : Return Value A string with the first character from each word in the receiver changed to its corresponding uppercase value, and all remaining characters set to their corresponding lowercase values. NSString *str = @"AlgeBra"; NSString *other = [str capitalizedString]; NSLog (@"Old: %@, New: %@", str, other); Edit: Just saw that you would like to remove accents as well. You can go through a series of steps: //

Best way to compare two int arrays of the same length?

為{幸葍}努か 提交于 2019-11-27 22:23:20
what is the best way to compare int arrays b and c with a: int a[] = {0,1,0,0,1}; int b[] = {0,1,0,0,1}; int c[] = {1,1,0,0,1}; b and c are just examples, assume they can be any combination of 0s and 1s. I am trying to detect arrays identical to a. I have googled this for a while and have not found a satisfactory answer. This is a beginners question I realise, thank you for your patience. Use the standard memcmp function from <string.h> . memcmp(a, b, sizeof(a)) == 0 whenever a and b are equal. If you mean int a[] = {0,1,0,0,1}; int b[] = {0,1,0,0,1}; int c[] = {1,1,0,0,1}; then memcmp(a, b,

Compare 2 excel files using Python

心已入冬 提交于 2019-11-27 21:41:40
I have two xlsx files as follows: value1 value2 value3 0.456 3.456 0.4325436 6.24654 0.235435 6.376546 4.26545 4.264543 7.2564523 and value1 value2 value3 0.456 3.456 0.4325436 6.24654 0.23546 6.376546 4.26545 4.264543 7.2564523 I need to compare all cells, and if a cell from file1 != a cell from file2 print that. import xlrd rb = xlrd.open_workbook('file1.xlsx') rb1 = xlrd.open_workbook('file2.xlsx') sheet = rb.sheet_by_index(0) for rownum in range(sheet.nrows): row = sheet.row_values(rownum) for c_el in row: print c_el How can I add the comparison cell of file1 and file2 ? The following

Compare two text files line by line [closed]

浪子不回头ぞ 提交于 2019-11-27 21:37:07
Beneath here i described a example Scenario: "FileA-Database.txt" contains the following names: KB200 KB300 KB400 "FileB-Slave.txt" contains the following names: KB600 KB200 KB400 KB700 I want to compare the "FileA-Database.txt" with "FileB-Slave.txt" and let the missing values be filled in automatically in the "FileA-Database.txt" file also i need to display the missing values in a text file called "Results.txt". The code needs to be compatible with C# (framework 4.0+) please!. I need a simple approach, mine doesnt work exactly the way i want it to: private void button_compare_Click(object

How can I compare two dates, return a number of days

淺唱寂寞╮ 提交于 2019-11-27 20:32:05
how can I compare two dates return number of days. Ex: Missing X days of the Cup. look my code. NSDateFormatter *df = [[NSDateFormatter alloc]init]; [df setDateFormat:@"d MMMM,yyyy"]; NSDate *date1 = [df dateFromString:@"11-05-2010"]; NSDate *date2 = [df dateFromString:@"11-06-2010"]; NSTimeInterval interval = [date2 timeIntervalSinceDate:date1]; //int days = (int)interval / 30; //int months = (interval - (months/30)) / 30; NSString *timeDiff = [NSString stringWithFormat:@"%dMissing%d days of the Cup",date1,date2, fabs(interval)]; label.text = timeDiff; // output (Missing X days of the Cup)

How to compare time part of datetime

醉酒当歌 提交于 2019-11-27 20:25:49
Let's say we have DateTime t1 = DateTime.Parse("2012/12/12 15:00:00.000"); and DateTime t2 = DateTime.Parse("2012/12/12 15:03:00.000"); How to compare it in C# and say which time is "is later than"? You can use the TimeOfDay property and use the Compare against it. TimeSpan.Compare(t1.TimeOfDay, t2.TimeOfDay) Per the documentation: -1 if t1 is shorter than t2. 0 if t1 is equal to t2. 1 if t1 is longer than t2. kaveman The < , <= , > , >= , == operators all work directly on DateTime and TimeSpan objects. So something like this works: DateTime t1 = DateTime.Parse("2012/12/12 15:00:00.000");

bash string compare to multiple correct values

会有一股神秘感。 提交于 2019-11-27 20:22:50
i have the following piece of bashscript: function get_cms { echo "input cms name" read cms cms=${cms,,} if [ "$cms" != "wordpress" && "$cms" != "meganto" && "$cms" != "typo3" ]; then get_cms fi } But no matter what i input (correct and incorrect values) it never calls the function again, because I only want to allow 1 of those 3 inputs. I have tried it with || with [ var != value ] or [ var != value1 ] or [ var != value1 ] but nothing works. Can someone point me in the right direction? Instead of saying: if [ "$cms" != "wordpress" && "$cms" != "meganto" && "$cms" != "typo3" ]; then say: if [[