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

2/6

Page

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

Which of the following is true about string concatenation in Java?

Select an option to see the answer and solution.

How do you find the index of the last occurrence of a substring in a string in Java?

Select an option to see the answer and solution.

In Java, what is the purpose of the endsWith() method of a String object?

Select an option to see the answer and solution.

What is the purpose of the toLowerCase() method of a String object in Java?

Select an option to see the answer and solution.

Which method is used to extract a substring from a string in Java?

Select an option to see the answer and solution.

In Java, what is the purpose of the isEmpty() method of a String object?

Select an option to see the answer and solution.

What is the result of the expression "Hello".toUpperCase().toLowerCase() in Java?

Select an option to see the answer and solution.

How do you check if a string contains a specific character in Java?

Select an option to see the answer and solution.

What is the purpose of the substring() method of a String object in Java?

Select an option to see the answer and solution.

How do you find the first index of a specified character in a string in Java?

Select an option to see the answer and solution.

The output of the following fraction of code is
public class Test{
        public static void main(String args[]){
	        String s1 = new String("Hello");
		String s2 = new String("Hellow");
		System.out.println(s1 = s2);
	}
}

Select an option to see the answer and solution.

What will be the output of the following program code?
class LogicalCompare{
        public static void main(String args[]){
                String str1 = new String("OKAY");
                String str2 = new String(str1);
                System.out.println(str1 == str2);
        }
}

Select an option to see the answer and solution.

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

Select an option to see the answer and solution.

Determine output:
public class Test{
        public static void main(String args[]){ 	
		String s1 = "SITHA";
		String s2 = "RAMA";
		System.out.println(s1.charAt(0) > s2.charAt(0));
        }
}

Select an option to see the answer and solution.

What could be output of the following fragment of code?
public class Test{
        public static void main(String args[]){ 
		String x = "hellow";
		int y = 9;
		System.out.println(x += y);
        } 
}

Select an option to see the answer and solution.

toString() method is defined in

Select an option to see the answer and solution.

The String method compareTo() returns

Select an option to see the answer and solution.

What will be the output?
String str1 = "abcde";
System.out.println(str1.substring(1, 3));

Select an option to see the answer and solution.

What is the output of the following println statement?
String str1 = "Hellow";
System.out.println(str1.indexOf('t'));

Select an option to see the answer and solution.

What will be the output of the following program?
public class Test{
        public static void main(String args[]){
		String str1 = "one";
		String str2 = "two";
		System.out.println(str1.concat(str2));
        }
}

Select an option to see the answer and solution.