String Manipulation Ques
String Manipulation Ques
String is a Final class; i.e once created the value cannot be altered. Thus String
objects are called immutable(not changeable).
The Java Virtual Machine(JVM) creates a memory location especially for Strings
called String Constant Pool. That’s why String can be initialized without ‘new’
keyword.
String class falls under java.lang.String hierarchy. But there is no need to import this
class. Java platform provides them automatically.
String reference can be overridden but that does not delete the content; i.e., if
String h1 = "hello";
h1 = "hello"+"world";
then "hello" String does not get deleted. It just loses its handle.
Multiple references can be used for same String but it will occur in the same place;
i.e., if
String s1 = "hello";
String s2 = "hello";
String s3 = "hello";
then only one pool for String “hello” is created in the memory with 3 references
- s1,s2,s3
QUESTIONS
2. String x = "Computer";
String y = "Applications";
System.out.println(x.substring(1,5));
3. String S1 = "Computer";
String S2 = "COMPUTER WORLD";
String S3 = "Computer world";
String S4 = "computer world";
System.out.println(S1 + " equals "+ S2 + "
" + S1.equals(S2));
System.out.println(S1 + " equals "+ S3 + "
" + S1.equals(S3));
System.out.println(S1 + " equals "+ S4 + "
" + S1.equals(S4));
5. System.out.println ("DEDICATE".compareTo("DEVOTE"));
6. boolean p;
p = ("BLUEJ".length() > "bluej".length()) ? true: false;
7. String x = "Computer";
String y = "Applications";
System.out.println(y + x.substring(5,y.length()));
9. String x = “Vision”;
String y = “2021”;
System.out.println(x + y);