Core java interview Questions You'll Most Likely Be Asked (Second Edition)


a. b. c. d. e. f. g. h. i. 137


Download 1.52 Mb.
Pdf ko'rish
bet53/171
Sana07.01.2023
Hajmi1.52 Mb.
#1081886
1   ...   49   50   51   52   53   54   55   56   ...   171
Bog'liq
Core JAVA Interview Questions Youll M...

136.
a.
b.
c.
d.
e.
f.
g.
h.
i.
137.
Name some commonly used methods from the String
class.
Answer:
The following are some commonly used methods from the String
class:
concat(): This is used to append a value to the current
String.
length(): This is used to find the length of the String, that is
the total number of characters in the String.
replace(): This is used to replace a particular character or
characters from a String with some other value.
substring(): This is used to obtain a substring of the current
string that begins from the specified position.
trim(): This is used to remove the whitespaces in a string.
toUpperCase(): This is used to convert all the characters in a
string to upper case.
toLowerCase(): This is used to convert all the characters in
a string to lower case.
equals(): This is used to compare the current String with the
specified String. It returns a boolean value which is the result
of comparison.
equalsIgnoreCase(): This is used to compare the current
String with the specified String irrespective of the case. It
returns a boolean value which is the result of comparison.
What is the difference between StringBuffer and
StringBuilder?
Answer:


138.
139.
Both StringBuffer and StringBuilder classes can be used to
perform String operations. They are both mutable unlike the
java.lang.String which is immutable. However, the StringBuilder
class is not thread safe i.e., StringBuilder methods are not
synchronized. That means, StringBuilder should not be used
when you execute two or more threads in an application. Also,
since StringBuilder it unsynchronized, it has a better performance
as compared to StringBuffer.

Download 1.52 Mb.

Do'stlaringiz bilan baham:
1   ...   49   50   51   52   53   54   55   56   ...   171




Ma'lumotlar bazasi mualliflik huquqi bilan himoyalangan ©fayllar.org 2024
ma'muriyatiga murojaat qiling