Strings
- Which of this method of class StringBuffer is used to concatenate the string representation to the end of invoking string?
-
View Hint View Answer Discuss in Forum
NA
Correct Option: C
append()
- Which of these class is used to create an object whose character sequence is mutable?
-
View Hint View Answer Discuss in Forum
NA
Correct Option: C
StringBuffer represents growable and writable character sequence.
- What is the output of this program?
public class Result
{
public static void main(String args[])
{ String str = "Interview Mania";
int K = str.indexOf('v');
int L = str.lastIndexOf('i');
System.out.print(K + " " + L);
}
}
-
View Hint View Answer Discuss in Forum
NA
Correct Option: C
indexOf() method returns the index of first occurrence of the character where as lastIndexOf() returns the index of last occurrence of the character.
- What is the output of this program?
public class Result
{
public static void main(String args[])
{
String str1 = "Interview Mania";
String str2 = str1.substring(0 , 9);
System.out.println(str2);
}
}
-
View Hint View Answer Discuss in Forum
NA
Correct Option: A
substring(0,9) returns the character from 0 th position to 8th position.
- What is the output of this program?
public class output
{
public static void main(String args[])
{
String str1 = "Intervzew Manza";
String str2 = str1.replace('z','i');
System.out.println(str2);
}
}
-
View Hint View Answer Discuss in Forum
NA
Correct Option: C
replace() method replaces all occurrences of one character in invoking string with another character. str1.replace(‘z’,’i’) replaces every occurrence of ‘z’ in hello by ‘i’, giving Interview Mania.