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

3/6

Page

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

String str1 = "Kolkata".replace('k', 'a');

In the above statement, the effect on string Kolkata is

Select an option to see the answer and solution.

The class string belongs to ................. package.

Select an option to see the answer and solution.

What will be the output?
public class Test{ 
        public static void main (String[] args){ 
		String test = "a1b2c3"; 
                String[] tokens = test.split("\\d"); 
                for(String s: tokens) 
                        System.out.print(s); 
	} 
}

Select an option to see the answer and solution.

How many objects will be created?
String a = new String("Examveda");
String b = new String("Examveda");
String c = "Examveda";
String d = "Examveda";

Select an option to see the answer and solution.

How many Constructor String class have?

Select an option to see the answer and solution.

What will be output?
String S1 = "S1 ="+ "123"+"456";
String S2 = "S2 ="+(123+456);

Select an option to see the answer and solution.

What will be the output of the following program code?
public class Test{
      public static void main(String args[]){
            String s = "what";
            StringBuffer sb = new StringBuffer("what");
            System.out.print(sb.equals(s)+","+s.equals(sb));
      }
}

Select an option to see the answer and solution.

What will be the output?
public class Test{
     public static void main(String args[]){
           Object myObj = new String[]{"one", "two", "three"};
           {
          for(String s : (String[])myObj) 
	        System.out.print(s + ".");
         }
     }
}

Select an option to see the answer and solution.

Determine output:
public class Test{
      public static void main(String args[]){
            String str = null;
            if(str.length() == 0){
                  System.out.print("1");
            }
            else if(str == null){
                  System.out.print("2");
            }
            else{
                  System.out.print("3");
            }
      }
}

Select an option to see the answer and solution.

Which of these methods is used to compare a specific region inside a string with another specific region in another string?

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.insert(1,"Java");
       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 c = "Hello i love java";
       boolean var;
       var = c.startsWith("hello");
       System.out.println(var);
    }
}

Select an option to see the answer and solution.

Which of these data type value is returned by equals() method of String class?

Select an option to see the answer and solution.

Which of the following are incorrect form of StringBuffer class constructor?

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 c = "  Hello World  ";
       String s = c.trim();
       System.out.println("\""+s+"\"");
    }
}

Select an option to see the answer and solution.

Which of the following statement is correct?

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 a = "hello i love java";
        System.out.println(a.indexOf('e')+" "+a.indexOf('a')+" "+a.lastIndexOf('l')+" "+a.lastIndexOf('v'));
    }
}

Select an option to see the answer and solution.

Which of these class is used to create an object whose character sequence is mutable?

Select an option to see the answer and solution.

Which of these methods can be used to convert all characters in a String into a character array?

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 i love java";
       String s2 = new String(s1);
       System.out.println((s1 == s2) + " " + s1.equals(s2));
    }
}

Select an option to see the answer and solution.