This section of our 1000+ Java MCQs focuses on searching and modifying a string of Java Programming Language. Show
1. Which of this method of class String is used to extract a substring from a String object? Answer: a 2. What will s2 contain after following lines of Java code? String s1 = "one"; String s2 = s1.concat("two") a) one Answer: c 3. Which of these method of class String is used to remove leading and trailing whitespaces? Answer: b 4. What is the value returned by function compareTo() if the invoking string is greater than the string compared? Answer: c if (s1 == s2) then 0, if(s1 > s2) > 0, if (s1 < s2) then < 0. 5. Which of the following statement is correct? Answer: a 6. What will be the output of the following Java program?
a) “”Hello
World”” Answer: c $ javac output.java $ java output "Hello World" 7. What will be the output of the following Java program?
a) one Answer: c $ javac output.java
$ java output
one two 8. What will be the output of the following Java program?
a) hello Answer: d $ javac output.java
$ java output
hewwo 9. What will be the output of the following Java program?
a) Hell Answer: a $ javac output.java
$ java output
Hell
10. What will be the output of the following Java program?
a) 4 8 Answer: c $ javac output.java $ java output 4 9 Sanfoundry Global Education & Learning Series – Java Programming Language. Next Steps:
Manish Bhojasia, a technology veteran with 20+ years @ Cisco & Wipro, is Founder and CTO at Sanfoundry. He lives in Bangalore, and focuses on development of Linux Kernel, SAN Technologies, Advanced C, Data Structures & Alogrithms. Stay connected with him at LinkedIn. Subscribe to his free Masterclasses at Youtube & technical discussions at Telegram SanfoundryClasses. Which of the following method call gives the position of the first occurrence of x in the string?The Java String class indexOf() method returns the position of the first occurrence of the specified character or string in a specified string.
Which of the following method call gives the position of the first occurrence of x in the string s1 A s1 indexOf x B s1 indexOf x N C s1 Index x 1 D s1 index x N?The charAt() method returns the character at the specified index in a string. The index of the first character is 0, the second character is 1, and so on.
What is the use of charAt () method Mcq?Explanation: charAt() is a method of class String which gives the character specified by the index. obj.
Which of the following methods will create string in Java Mcq?The intern() and toString() methods are of String class. Hence, the correct answer is option (c).
|