387). Which of these class is used to create an object whose character sequence is mutable?
[A]String()
[B]StringBuffer()
[C]String() & StringBuffer()
[D]None of the mentioned
Show Answer
Correct Answer: StringBuffer()
Notes:
Answer: b
Explanation: StringBuffer represents growable and writable character sequence.
388). Which of this method of class StringBuffer is used to concatenate the string representation to the end of invoking string?
[A]concat()
[B] append()
[C]join()
[D]concatenate()
Show Answer
Correct Answer: append()
Notes:
Answer: b
Explanation: None.
389). Which of these method of class StringBuffer is used to find the length of current character sequence?
[A]length()
[B]Length()
[C]capacity()
[D]Capacity()
Show Answer
Correct Answer: length()
Notes:
Answer: a
Explanation: None.
390). What is the string contained in s after following lines of Java code?
StringBuffer s new StringBuffer("Hello");
s.deleteCharAt(0);
[A]Hell
[B]ello
[C]Hel
[D]llo
Show Answer
Correct Answer: ello
Notes:
Answer: b
Explanation: deleteCharAt() method deletes the character at the specified index location and returns the resulting StringBuffer object.
391). Which of the following statement is correct?
StringBuffer s new StringBuffer("Hello");
s.deleteCharAt(0);
[A]reverse() method reverses all characters
[B] reverseall() method reverses all characters
[C] replace() method replaces first occurrence of a character in invoking string with another character
[D] replace() method replaces last occurrence of a character in invoking string with another character
Show Answer
Correct Answer: reverse() method reverses all characters
Notes:
Answer: a
Explanation: reverse() method reverses all characters. It returns the reversed object on which it was called.
392). What will be the output of the following Java program?
class output
{
public static void main(String args[])
{
String a = "hello i love java";
System.out.println(a.indexOf('e')+" "+a.indexOf('a')+" "+a.lastIndexOf('l')+" "+a.lastIndexOf('v'));
}
}
[A]6 4 6 9
[B]5 4 5 9
[C]7 8 8 9
[D] 1 14 8 15
Show Answer
Correct Answer: 1 14 8 15
Notes:
Answer: d
Explanation: indexof(ācā) and lastIndexof(ācā) are pre defined function which are used to get the index of first and last occurrence of
the character pointed by c in the given array.
Output:$ javac output.java
$ java output
1 14 8 15
393). What will be the output of the following Java program?
class output
{
public static void main(String args[])
{
StringBuffer c = new StringBuffer("Hello");
c.delete(0,2);
System.out.println(c);
}
}
[A]He
[B]Hel
[C]lo
[D]llo
Show Answer
Correct Answer: llo
Notes:
Answer: d
Explanation: delete(0,2) is used to delete the characters from 0 th position to 1 st position.
Output:
$ javac output.java
$ java output
llo
394). What will be the output of the following Java program?
class output
{
public static void main(String args[])
{
StringBuffer c = new StringBuffer("Hello");
StringBuffer c1 = new StringBuffer(" World");
c.append(c1);
System.out.println(c);
}
}
[A]Hello
[B]World
[C]Helloworld
[D]Hello World
Show Answer
Correct Answer: Hello World
Notes:
Answer: d
Explanation: append() method of class StringBuffer is used to concatenate the string representation to the end of invoking string.
Output:
$ javac output.java
$ java output
Hello World
395). What will be the output of the following Java program?
class output
{
public static void main(String args[])
{
StringBuffer s1 = new StringBuffer("Hello");
StringBuffer s2 = s1.reverse();
System.out.println(s2);
}
}
[A]Hello
[B]olleH
[C]HelloolleH
[D]olleHHello
Show Answer
Correct Answer: olleH
Notes:
Answer: b
Explanation: reverse() method reverses all characters. It returns the reversed object on which it was called.
Output:
$ javac output.java
$ java output
olleH
396). What will be the output of the following Java program?
class output
{
class output
{
public static void main(String args[])
{
char c[]={'A', '1', 'b' ,' ' ,'a' , '0'};
for (int i = 0; i < 5; ++i)
{
i++;
if(Character.isDigit(c[i]))
System.out.println(c[i]+" is a digit");
if(Character.isWhitespace(c[i]))
System.out.println(c[i]+" is a Whitespace character");
if(Character.isUpperCase(c[i]))
System.out.println(c[i]+" is an Upper case Letter");
if(Character.isLowerCase(c[i]))
System.out.println(c[i]+" is a lower case Letter");
i++;
}
}
}
[A] a is a lower case Letter is White space character
[B] b is a lower case Letter is White space character
[C] 1 is a digit a is a lower case Letter
[D] a is a lower case Letter 0 is a digit
Show Answer
Correct Answer: 1 is a digit a is a lower case Letter
Notes:
Answer: c
Explanation: Character.isDigit(c[i]), Character.isUpperCase(c[i]), Character.isWhitespace(c[i]) are the function of library java.lang they are used to find whether the given character is of specified type or not. They return true or false i:e Boolean variable.
Output:
$ javac output.java
$ java output
1 is a digit
a is a lower case Letter