Java String Faqs

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

10) What is the difference between String and StringBuffer in java?

11) What is the difference between StringBuffer and StringBuilder in java?

12) What does intern method in java?

13) How to convert String to int in java?

14) How to convert int to String in java?

15) How to convert String to Date in java?

16) How to Optimize Java String Creation?

17) Java Program to check whether two Strings are anagram or not

18) Java program to find the percentage of uppercase, lowercase, digits and special characters in a String

19) How to convert String to Integer and Integer to String in Java

20) Java Program to find duplicate characters in a String

21) Java Program to prove that strings are immutable in java

22) Java Program to remove all white spaces from a String

23) Java Program to check whether one String is a rotation of another

24) Java Program to count the number of words in a String

25) Java Program to reverse a given String with preserving the position of space

26) How to swap two String variables without third variable

27) How to remove a particular character from a String

Input Required

This code uses input(). Please provide values below: