Searching And Modifying A String(Computer Science > Java Program ) Questions and Answers
Explanation:-
Answer: Option C. -> String associated with obj1toString() is method of class Object, since it is superclass of every class, every object has this
method. toString() returns the string associated with the calling object.
output:
$ javac Output.java
$ java Output
A@1cd2e5f
Explanation:-
Answer: Option D. -> accompareTo() function returns zero when both the strings are equal, it returns a value less than
zero if the invoking string is less than the other string being compared and value greater than
zero when invoking string is greater than the string compared to.
output:
$ javac output.java
$ java output
ac
Explanation:-
Answer: Option D. -> 4 3None.
output:
$ javac String_demo.java
$ java String_demo
4 3
Explanation:-
Answer: Option B. -> e"hello" is a String literal, method charAt() returns the character specified at the index position.
Character at index position 1 is e of hello, hence ch contains e.
output:
$ javac output.java
$ java output
e
Explanation:-
Answer: Option C. -> 4 9indexOf() method returns the index of first occurrence of the character where as lastIndexOf()
returns the index of last occurrence of the character.
output:
$ javac output.java
$ java output
4 9
Explanation:-
Answer: Option B. -> BCDascii is an array of integers which contains ascii codes of Characters A, B, C, D. String(ascii, 1, 3)
is an constructor which initializes s with Characters corresponding to ascii codes stored in array ascii,
starting position being given by 1 & ending position by 3, Thus s stores BCD.
output:
$ javac String_demo.java
$ java String_demo
BCD
Explanation:-
Answer: Option A. -> Hellsubstring(0,4) returns the character from 0 th position to 3 rd position.
output:
$ javac output.java
$ java output
Hell
Explanation:-
Answer: Option D. -> abcString(chars) is a constructor of class string, it initializes string s with the values stored in character
array chars, therefore s contains "abc".
output:
$ javac String_demo.java
$ java String_demo
abc
Explanation:-
Answer: Option C. -> true falseNone.
Output:
$ javac output.java
$ java output
true false
Explanation:-
Answer: Option D. -> false trueThe == operator compares two object references to see whether they refer to the same instance,
where as equals() compares the content of the two objects.
Output:
$ javac output.java
$ java output
false true