How do you compare two strings? any predefined method for
this?
Answers were Sorted based on User's Feedback
You can compare the values of 2 Strings by following
methods of String class:-
Eg:- String a="abc"; String b="abc";
1> .equals() method it will return a boolean value.
eg:- if(a.equals(b)) will return true.
2> .compareTo() method.If the two java strings are exactly
the same, the compareTo method will return a value of 0
(zero).
eg:- if (a.compareTo(b) == 0){
// this line will print
System.out.println("a and b strings are the same.")
}
| Is This Answer Correct ? | 4 Yes | 0 No |
explain copyonwritearraylist and when do we use copyonwritearraylist?
what is default constructor and parameterised constructor with example?
How do you use compareto method?
what is the difference between object and class
What is the purpose of the runtime class in java programming?
What are Advatages of Overloading and Overridding.
Which methods cannot be overridden in java?
what is servlet filter?
What modifiers may be used with a top-level class?
What does split function do in java?
When we r go to abstract class and when we go to Interface? i have confusion this question while in interview plz clarify
import java.io.*; class Demo { public static void main(String args[]) { File f=new File("1234.msg"); String arr[]=f.list(); System.out.println(arr.length); } }