Java String FAQs or Interview Questions

A list of top Java String FAQs (Frequently Asked Questions) or interview questions are given below. These questions can be asked by the interviewer.

1) How many objects will be created in the following code?

String s1="w3cschoool";
String s2="w3cschoool";

Answer: Only one.


2) What is the difference between equals() method and == operator?

The equals() method matches content of the strings whereas == operator matches object or reference of the strings.


3) Is String class final?

Answer: Yes.

4) How to reverse String in java?

Input:

this is w3cschoool

Output:

tnioptavaj si siht

5) How to check Palindrome String in java?

Input:

nitin

Output:

true

Input:

jatin

Output:

false

6) Write a java program to capitalize each word in string?

Input:

this is w3cschoool

Output:

This Is Javatpoint

7) Write a java program to reverse each word in string?

Input:

this is w3cschoool

Output:

siht si tnioptavaj

8) Write a java program to tOGGLE each word in string?

Input:

this is w3cschoool

Output:

tHIS iS jAVATPOINT

9) Write a java program reverse tOGGLE each word in string?

Input:

this is w3cschoool

Output:

sIHT sI tNIOPTAVAJ

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





Contact US

Email:[email protected]

Java String FAQs
10/30