Do we have notEquals() method in String API?
Unfortunately the answer is 'No' but we can achieve it with negating equals() method.
The following example will demonstrate this concept.
notEquals using Java String API
public class StringNotEquals {
public static void main(String[] args) {
String stringOne = "January";
String stringTwo = "March";
if(!stringOne.equals(stringTwo)){
System.out.printf("%s not equals to %s",stringOne, stringTwo);
}
else{
System.out.printf("%s equals to %s",stringOne, stringTwo);
}
}
}
Output: January not equals to March
No comments:
Post a Comment