String Handling Interview Questions and Answers in Java - 1
What is the difference between String, String Buffer and StringBuilder?
String is a immutable class
StringBuffer is a mutable class
StringBuilder is a mutable class
|New Object is created every time when modified.||No new object is created, modification is done in existing one.||
No new object is created, modification is done in existing one.
|Use String if you require immutability||Use StringBuffer in java if you need mutable + thread safety.||
Use StringBuilder in java if you require mutable + without thread safety
Why String is immutable or final in Java?
There are several benefits of String because it’s immutable and final.
String Pool is possible because String is immutable in java.
It increases security because any hacker can’t change its value and it’s used for storing sensitive information such as database username, password etc.
Since String is immutable, it’s safe to use in multi threading and we don’t need any synchronization.
Strings are used in java classloader and immutability provides security that correct class is getting loaded by Classloader.
How to split String in java?
We can use split (String regex) to split the String into String array based on the provided regular expression.
What is String in Java?
String is a Class in java and defined in java.lang package. It’s not a primitive data type like int and long. String class represents characters Strings.
String is used in almost all the Java application and there are some interesting facts that we should know about String.
String is immutable and final in Java and JVM uses String Pool to store all the String Objects.
String is the way we can instantiate a String object using double quotes and overloading of “+” operator for concatenation.
Write a function to find out longest palindrome in a given string?
A String can contains palindrome strings in it and to find longest palindrome in given String is a programming question.
7000+ Question Tags Exercises with Answers Pdf More
7000+ TNPSC Group 4 Study Material Pdf free Download More
7000+ TNPSC Group 4 General English Question Paper with Answers More
7000+ Prepositions Exercises for Class 10 with Answers Pdf More
7000+ Prefix and Suffix MCQs with Answers Pdf More
1000+ Difficult Mathematical Puzzles with Solutions More
Windows XP Objective Questions and Answers More
Top 100+ Advanced SQL Interview Questions 2020-2021 More
Aptitude Odd Man Out Questions Answers for Competitive Exams More
Indian Freedom Struggle Quiz Questions and Answers More