Vidyalelo
Java Programming · all questions

Strings
practice.

Practice every MCQ with options. Use Show answers when you want the correct option and solution.

107

Questions

6/6

Page

Pick an option on a question to see the right answer and solution.

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);
    }
}

Select an option to see the answer and solution.

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);
    }
}

Select an option to see the answer and solution.

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'));
    }
}

Select an option to see the answer and solution.

What will s2 contain after following lines of Java code?
 String s1 = "one";
String s2 = s1.concat("two")

Select an option to see the answer and solution.

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());
    }
}

Select an option to see the answer and solution.

Which of these operators can be used to concatenate two or more String objects?

Select an option to see the answer and solution.

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));
    }
}

Select an option to see the answer and solution.