Unique Set of 25 Java Strings MCQ question of ICSE X Computer Applications

Unique Set of 25 Java Strings MCQ question of ICSE X Computer Applications

1.  Which method is used to compare two strings, ignoring their case, for equality in Java? 

   a.  compare() 

   b.  equals() 

   c.  equalsIgnoreCase() 

   d.  compareIgnoreCase() 


2.  What does the  split()  method in Java do for a string? 

   a. Breaks the string into an array of substrings based on a specified delimiter.

   b. Concatenates two strings.

   c. Reverses the characters in the string.

   d. Checks if the string starts with a specific character.



3.  In Java, how do you convert an array of characters to a string? 

   a.  String.valueOf(charArray) 

   b.  arrayToString(charArray) 

   c.  convertToString(charArray) 

   d.  new String(charArray) 


4.  What is the output of the following code snippet? 

      java

   String str = "Java";

   System.out.println(str.substring(0, 2));

      

   a.  Ja 

   b.  Jav 

   c.  av 

   d.  Ja  (index out of bounds error)


5.  Which method is used to check if a string contains a specified sequence of characters in Java? 

   a.  contains() 

   b.  hasSubstring() 

   c.  includes() 

   d.  checkSubstring() 


6.  What is the purpose of the  StringBuffer  class in Java? 

   a. Represents an immutable sequence of characters.

   b. Represents a mutable sequence of characters.

   c. Converts a string to an array of characters.

   d. Checks if a string contains specific characters.


7.  What is the result of the following expression? 


   "abc".compareToIgnoreCase("ABC");

      

   a.  0 

   b. Positive integer

   c. Negative integer

   d. Compilation Error


8.  How do you check if a string ends with a specific suffix in Java? 

   a.  endsWith() 

   b.  endsWithString() 

   c.  endWith() 

   d.  checkEnd() 


9.  What is the purpose of the  valueOf()  method in Java? 

   a. Converts different types of values to a string representation.

   b. Converts a string to an integer.

   c. Checks if two strings are equal.

   d. Converts a string to uppercase.


10.  Which method is used to obtain the character at a specific index in a string in Java? 

    a.  charAt() 

    b.  getChar() 

    c.  characterAt() 

    d.  charAtIndex() 



11.  What is the output of the following code snippet? 


    String str = "Hello World";

    System.out.println(str.indexOf("o", 5));

       

    a.  7 

    b.  4 

    c.  2 

    d.  -1 


12.  How do you check if two strings are equal in Java, considering their case? 

    a.  equals() 

    b.  equalsIgnoreCase() 

    c.  compare() 

    d.  isEqual() 


13.  Which method is used to convert all the characters in a string to lowercase in Java? 

    a.  toLowerCase() 

    b.  toLower() 

    c.  lowerCase() 

    d.  caseLower() 


14.  What is the purpose of the  concat()  method in Java? 

    a. Concatenates two strings.

    b. Reverses the characters in a string.

    c. Converts a string to uppercase.

    d. Splits a string into substrings.


15.  What is the output of the following code snippet?

    String str = "Programming";

    System.out.println(str.substring(3, 9));

       

    a.  gramm 

    b.  ogramm 

    c.  ogram 

    d.  rammin 


16.  How do you replace all occurrences of a substring in a string in Java? 

    a.  replaceAll() 

    b.  replaceFirst() 

    c.  replace() 

    d.  substitute() 


17.  Which method is used to compare two strings lexicographically in Java, considering their case? 

    a.  compareTo() 

    b.  compare() 

    c.  equals() 

    d.  isEqual() 


18.  What is the purpose of the  trim()  method in Java? 

    a. Removes leading and trailing spaces from a string.

    b. Converts the string to uppercase.

    c. Reverses the characters in the string.

    d. Returns the length of the string.


19.  What does the  startsWith()  method in Java check? 

    a. If a string starts with a specific character.

    b. If a string starts with a specific substring.

    c. If a string ends with a specific character.

    d. If a string ends with a specific substring.


20.  What is the output of the following code snippet? 

   

    String str1 = "Hello";

    String str2 = "Hello";

    System.out.println(str1 == str2);

       

    a.  true 

    b.  false 

    c. Compiler Error

    d. Runtime Error


21.  How do you obtain the last index of a specified character in a string in Java? 

    a.  lastIndexOf() 

    b.  findLastIndex() 

    c.  searchLastIndex() 

    d.  indexOfLast() 



22.  What is the result of the following expression? 


    "Java".substring(1, 3).equals("av");

       

    a.  true 

    b.  false 

    c. Compiler Error

    d. Runtime Error


23.  Which method is used to convert a numeric value to a string in Java? 

    a.  toString() 

    b.  convertToString() 

    c.  stringify() 

    d.  valueOf() 


24.  What is the purpose of the  toUpperCase()  method in Java? 

    a. Converts the string to lowercase.

    b. Reverses the characters in the string.

    c. Converts the string to uppercase.

    d. Returns the length of the string.


25.  What is the output of the following code snippet? 

      

    String str = "Hello World";

    System.out.println(str.lastIndexOf("o", 8));

       

    a.  7 

    b.  4 

    c.  2 

    d.  -1 



1. c, 2. a, 3. d, 4. a, 5. a, 6. b, 7. b, 8. b, 9. a, 10. a,

11. a, 12. b, 13. a, 14. a, 15. a, 16. a, 17. a, 18. a, 19. a, 20. a,

21. b, 22. a, 23. a, 24. c, 25. a

Comments