comapring a '-' charcter
In my program I am reading some data of type String,int. Some values are empty. There I am entering - character. This "-" character indicates that the field is empty. Here I have to compare this current read data with previous data. If I found "-" in any one of the operator where I am comparing I don't update otherwise there is a need of updation.
Here I am getting the problem.
I wrote the code like this:
String s2=author[k].getDept(); // reading the input.
String t2=author[l].getDept(); // this input field may contain "-" as a input string
System.out.println("Dept: "+k+"is "+s2+"Dept: "+l+"is "+t2); // for verification purpose
if(s2=="-" || t2=="-")
if(s2!="-" && t2!="-")
System.out.println("Crossed if condition");
weightBetweenAuthors[k][l] += 1;
weightBetweenAuthors[l][k] += 1;
System.out.println("wg b/w au["+k+"]["+l+"]: "+weightBetweenAuthors[k][l]+ "["+l+"
]["+ k+"]: "+weightBetweenAuthors[l][k]); // just printing updated values
Here what happens is even the string is "-" it is not entering the if stmt and executing the else part and printing
Crossed if condition
and printing updated value.
In this part the mistake is. But what is the mistake I am not getting. The input is of type String thats why in comparison I kept that - character in double quotes.
please respond fast.
You can't compare a string with "==", you have to use the string equals() method...