How many Java String objects are created in following code snippet?
String str1 = new String("Happy");
String str2 = new String("Happy");
String str3 = "Happy"
String str4 =
"Happy":
Answers
Home / Interview / Java String Interview Questions with Answers
Java String Interview Questions with Answers
All of us must have gone though interview questions related to String class in java. These String interview questions range from immutability to memory leak issues. I will try to cover such questions in this post.
Frequently asked String Interview Questions
1. Is String keyword in Java?
2. Why are strings immutable?
3. What is String constant pool?
4. Keyword 'intern' usage
5. Matching Regular expressions?
6. String comparison with equals() and '=='?
7. Memory leak issue in String class
8. How does String work in Java?
9. What are different ways to create String Object?
10. How to check if String is Palindrome.
11. How to remove or replace characters from String.
12. How to make String upper case or lower case?
13. How to compare two Strings in java program?
14. Can we use String in the switch case?
15. Write a program to print all permutations of String?
16. Write a java program to reverse each word of a given string??
17. How to Split String in java?
18. Why is Char array preferred over String for storing password?
19. Is String thread-safe in Java
20. Why String is popular HashMap key in Java
21. Difference between String, StringBuffer and StringBuilder?
22. How to concatenate multiple strings.
23. How many objects will be created with string initialization code?
24. How do you count the number of occurrences of each character in a string?
25. Write a java program to reverse a string?
String str1 = new String("Happy")