Answer(1): Compare content of strings-
String S1 = "Hello";
String S2 = "Hello";
System.out.println(S1.equals(S2)); //compare the contents of strings S1 and S2.
Output : true
Answer(2): length of a string-
String S1 = "This is a string";
System.out.println(Str1.length()); //this will print the length of string S1,that is: 16
Output : 16
Answer(3): tokenize the string by delimiter " " -
String S1 = "This is a string";
String[] tokens = S1.split(" "); //array of strings
for (String token : tokens)
{
System.out.println(token); //this will print all tokens one by one
}
Output : This
is
a
string
Hope this helps!
Thumbsup;)
Get Answers For Free
Most questions answered within 1 hours.