Below are some frequently asked questions (FAQs) or common interview questions related to Java Strings that interviewers may ask:
1) How many objects will be created in the following code?
Example
String s1="Hello World";
String s2="Hello World";
2) What is the difference between equals method and == operator?
The method equals compares the contents of strings, while the == operator compares the object or reference of the strings.
3) Is String class final?
4) How to reverse String in java?
Input:
Example
this is java programming
Output:
Output
rezilausiv nohtyp si siht
5) How to check Palindrome String in java?
Input:
Output:
Input:
Output:
6) Write a java program to capitalize each word in string?
Input:
Example
this is java programming
Output:
Output
This Is Java Programming
7) Write a java program to reverse each word in string?
Input:
Example
this is java programming
Output:
Output
siht si nohtyp rezilausiv
8) Write a java program to tOGGLE each word in string?
Input:
Example
this is java programming
Output:
Output
tHIS iS hELLO wORLD
9) Write a java program reverse tOGGLE each word in string?
Input:
Example
this is java programming
Output:
Output
sIHT sI nOHTYP rEZILAUSIV