Question 1 of 25
Hints left: 3
Q1
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);
Q2
Which of this method of class StringBuffer is used to get the length of the sequence of characters?
Q3
Which of these methods of class String is used to check whether a given object starts with a particular string literal?
Q4
What will be the output of the following Java program? class output { public static void main(String args[]) { String s = "Hello World"; int i = s.indexOf('o'); int j = s.lastIndexOf('l'); System.out.print(i + " " + j); } }
Q5
Which of this method of class StringBuffer is used to concatenate the string representation to the end of invoking string?
Q6
What will be the output of the following Java code? class output { public static void main(String args[]) { char ch; ch = "hello".charAt(1); System.out.println(ch); } }
Q7
What is the string contained in s after following lines of Java code? StringBuffer s new StringBuffer("Hello"); s.deleteCharAt(0);
Q8
Which of these is an incorrect statement?
Q9
Which of this method of class String is used to extract a substring from a String object?
Q10
Which of these constructors is used to create an empty String object?
Q11
What will be the output of the following Java program? class output { public static void main(String args[]) { String s1 = "Hello World"; String s2 = s1.substring(0 , 4); System.out.println(s2); } }
Q12
Which of these method of class StringBuffer is used to find the length of current character sequence?
Q13
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); } }
Q14
What will be the output of the following Java program? class output { class output { public static void main(String args[]) { char c[]={'A', '1', 'b' ,' ' ,'a' , '0'}; for (int i = 0; i < 5; ++i) { i++; if(Character.isDigit(c[i])) System.out.println(c[i]+" is a digit"); if(Character.isWhitespace(c[i])) System.out.println(c[i]+" is a Whitespace character"); if(Character.isUpperCase(c[i])) System.out.println(c[i]+" is an Upper case Letter"); if(Character.isLowerCase(c[i])) System.out.println(c[i]+" is a lower case Letter"); i++; } } }
Q15
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); } }
Q16
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); } }
Q17
Which of these class is superclass of String and StringBuffer class?
Q18
What will s2 contain after following lines of Java code? StringBuffer s1 = "one"; StringBuffer s2 = s1.append("two")
Q19
Which of this method of class StringBuffer is used to reverse sequence of characters?
Q20
Which of these method of class String is used to extract more than one character at a time a String object?
Q21
What is the value returned by function compareTo() if the invoking string is greater than the string compared?
Q22
Which of this method of class String is used to obtain a length of String object?
Q23
What is the value returned by function compareTo() if the invoking string is less than the string compared?
Q24
Which of these method of class String is used to extract a single character from a String object?
Q25
What will be the output of the following Java program? class String_demo { public static void main(String args[]) { int ascii[] = { 65, 66, 67, 68}; String s = new String(ascii, 1, 3); System.out.println(s); } }