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

4/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[])
    { 
       String s1 = "Hello";
       String s2 = s1.replace('l','w');
       System.out.println(s2);
    }
}

Select an option to see the answer and solution.

Which of these method of class String is used to remove leading and trailing whitespaces?

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 sb=new StringBuffer("Hello");  
        sb.replace(1,3,"Java");  
        System.out.println(sb);
    }  
}

Select an option to see the answer and solution.

In the following Java code, which code fragment should be inserted at line 3 so that the output will be: "123abc 123abc"?
1. StringBuilder sb1 = new StringBuilder("123");
2. String s1 = "123";
3.  // insert code here
4. System.out.println(sb1 + " " + s1);

Select an option to see the answer and solution.

Which of these methods of class String is used to check whether a given object starts with a particular string literal?

Select an option to see the answer and solution.

Which of these method of class StringBuffer is used to find the length of current character sequence?

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 c = "Hello i love java";
       int start = 2;
       int end = 9;
       char s[]=new char[end-start];
       c.getChars(start,end,s,0);
       System.out.println(s);
    }
}

Select an option to see the answer and solution.

Which of these class is superclass of String and StringBuffer class?

Select an option to see the answer and solution.

Which of these constructors is used to create an empty String object?

Select an option to see the answer and solution.

Which of this method of class StringBuffer is used to reverse sequence of characters?

Select an option to see the answer and solution.

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

Select an option to see the answer and solution.

Which of this method of class StringBuffer is used to concatenate the string representation to the end of invoking string?

Select an option to see the answer and solution.

What is the value returned by function compareTo() if the invoking string is less than the string compared?

Select an option to see the answer and solution.

What is the value returned by function compareTo() if the invoking string is greater than the string compared?

Select an option to see the answer and solution.

What will be the output of the following Java program?
class String_demo 
{
    public static void main(String args[])
    {
        char chars[] = {'a', 'b', 'c'};
        String s = new String(chars);
        System.out.println(s);
    }
}

Select an option to see the answer and solution.

Which of this method of class StringBuffer is used to get the length of the sequence of characters?

Select an option to see the answer and solution.

Which of these method of class String is used to extract a single character from a String object?

Select an option to see the answer and solution.

What will be the output of the following Java program?
class output 
{
    public static void main(String args[])
    { 
       String s1 = "one";
       String s2 = s1 + " two";
       System.out.println(s2);
    }
}

Select an option to see the answer and solution.

Which of this method of class String is used to extract a substring from a String object?

Select an option to see the answer and solution.

Which of these method of class String is used to extract more than one character at a time a String object?

Select an option to see the answer and solution.