How to compare strings in java?
Answer / Avinash Kumar Gupta
In Java, you can compare two strings using the `equals()` method. Here's an example:
```java
String str1 = "Hello";
String str2 = "Hello";
if (str1.equals(str2)) {
System.out.println("The strings are equal.");
} else {
System.out.println("The strings are not equal.");
}
```
This will output: `"The strings are equal."` if both str1 and str2 contain the exact same characters.
| Is This Answer Correct ? | 0 Yes | 0 No |
What is interface and its use?
Can we use a switch statement with strings?
What is functional interface in javatpoint?
What is the symbol for average?
What is an abstract class and what is it’s purpose?
What is r in java?
How many types of literals are there in JAVA?
How do you achieve singleton?
How can you add and remove nodes in jtree?
What are different access specifiers in java? Explain
WAP to illustrate the use of interface
In which order the iterator iterates over collection?