1. 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);
}
}
class output
{
public static void main(String args[])
{
StringBuffer s1 = new StringBuffer("Hello");
StringBuffer s2 = s1.reverse();
System.out.println(s2);
}
}
2. What will be the output of the following Java code?
class output
{
public static void main(String args[])
{
StringBuffer s1 = new StringBuffer("Hello");
s1.setCharAt(1,'x');
System.out.println(s1);
}
}
class output
{
public static void main(String args[])
{
StringBuffer s1 = new StringBuffer("Hello");
s1.setCharAt(1,'x');
System.out.println(s1);
}
}
3. What will be the output of the following Java code?
class output
{
public static void main(String args[])
{
String a = "hello i love java";
System.out.println(a.indexOf('i')+" "+a.indexOf('o') +" "+a.lastIndexOf('i')+" "+a.lastIndexOf('o'));
}
}
class output
{
public static void main(String args[])
{
String a = "hello i love java";
System.out.println(a.indexOf('i')+" "+a.indexOf('o') +" "+a.lastIndexOf('i')+" "+a.lastIndexOf('o'));
}
}
4. What will s2 contain after following lines of Java code?
String s1 = "one";
String s2 = s1.concat("two")
String s1 = "one";
String s2 = s1.concat("two")
5. What will be the output of the following Java code?
class output
{
public static void main(String args[])
{
StringBuffer c = new StringBuffer("Hello");
System.out.println(c.length());
}
}
class output
{
public static void main(String args[])
{
StringBuffer c = new StringBuffer("Hello");
System.out.println(c.length());
}
}
6. Which of these operators can be used to concatenate two or more String objects?
7. What will be the output of the following Java code?
class output
{
public static void main(String args[])
{
String s1 = "Hello";
String s2 = new String(s1);
String s3 = "HELLO";
System.out.println(s1.equals(s2) + " " + s2.equals(s3));
}
}
class output
{
public static void main(String args[])
{
String s1 = "Hello";
String s2 = new String(s1);
String s3 = "HELLO";
System.out.println(s1.equals(s2) + " " + s2.equals(s3));
}
}
Read More Section(Strings)
Each Section contains maximum 100 MCQs question on Strings. To get more questions visit other sections.