25 Unique MCQ Questions on Java Strings for ICSE 10th Computer Applications Subject

 


25 Unique MCQ Questions on Java Strings for ICSE 10th Computer Applications Subject

1.  How do you concatenate two strings in Java without using the  concat()  method? 

   a.  s1 + s2 

   b.  s1.concat(s2) 

   c.  concat(s1, s2) 

   d.  join(s1, s2) 


2.  Which method is used to find the last index of a specified character in a string? 

   a.  lastIndexOf() 

   b.  findLast() 

   c.  searchLast() 

   d.  indexOfLast() 


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


   String str = "Programming";

   System.out.println(str.substring(4));

      

   a.  Gramming 

   b.  ogramming 

   c.  Programming 

   d.  ramming 


4.  What does the  equalsIgnoreCase()  method do in Java? 

   a. Compares two strings ignoring their case.

   b. Checks if a string is equal to "ignoreCase".

   c. Converts a string to lowercase.

   d. Converts a string to uppercase.


5.  Which of the following methods is used to convert a string to an integer in Java? 

   a.  parseInt() 

   b.  toInteger() 

   c.  stringToInt() 

   d.  valueOfInt() 


6.  What is the purpose of the  intern()  method in Java? 

   a. Converts the string to uppercase.

   b. Returns the length of the string.

   c. Interns the string, returning a canonical representation.

   d. Compares two strings for equality.


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


   String str = "Hello";

   System.out.println(str.endsWith("lo"));

      

   a.  true 

   b.  false 

   c. Compiler Error

   d. Runtime Error


8.  How do you convert a string to a primitive data type in Java? 

   a. Use the  parse  methods (e.g.,  Integer.parseInt() )

   b. Use the  convert  method (e.g.,  String.convert() )

   c. Use the  toPrimitive  method (e.g.,  string.toPrimitive() )

   d. Use the  primitive  method (e.g.,  string.primitive() )


9.  What is the result of the following expression? 


   "abc".compareTo("def");

      

   a. Negative integer

   b. Positive integer

   c. Zero

   d. Compilation Error


10.  What is the purpose of the  codePointAt()  method in Java? 

    a. Returns the Unicode code point of the specified index.

    b. Returns the ASCII code of the specified character.

    c. Converts a character to its binary representation.

    d. Checks if a character is a digit.


11.  How do you check if a string contains only numeric characters in Java? 

    a.  str.isNumeric() 

    b.  str.containsNumeric() 

    c.  str.matches("[0-9]+") 

    d.  str.checkNumeric() 


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


    String str = "abc";

    System.out.println(str.replace("b", "x"));

       

    a.  axc 

    b.  ax 

    c.  abc 

    d. Compiler Error


13.  Which method is used to convert a string to a double in Java? 

    a.  parseDouble() 

    b.  toDouble() 

    c.  stringToDouble() 

    d.  valueOfDouble() 


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

    a. Checks if a string matches a regular expression.

    b. Checks if two strings are identical.

    c. Converts a string to uppercase.

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


15.  What does the  replaceFirst()  method do in Java? 

    a. Replaces the first occurrence of a substring with another substring.

    b. Replaces all occurrences of a substring with another substring.

    c. Reverses the characters in the string.

    d. Converts the string to uppercase.



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


    String str = "Java Programming";

    System.out.println(str.lastIndexOf("a", 5));

       

    a.  1 

    b.  5 

    c.  7 

    d.  11 


17.  How do you convert a string to a character in Java? 

    a.  charAt() 

    b.  toChar() 

    c.  stringToChar() 

    d.  convertToChar() 


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


    String str = "Hello";

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

       

    a.  e 

    b.  l 

    c.  el 

    d.  H 


19.  Which method is used to convert a string to a boolean in Java? 

    a.  parseBoolean() 

    b.  toBoolean() 

    c.  stringToBoolean() 

    d.  valueOfBoolean() 


20.  What is the purpose of the  regionMatches()  method in Java? 

    a. Compares two strings for equality, ignoring case.

    b. Compares specific regions of two strings for equality.

    c. Checks if a string ends with a specific substring.

    d. Checks if a string starts with a specific substring.


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


    String str = "Java Programming";

    System.out.println(str.toUpperCase().startsWith("JAVA"));

       

    a.  true 

    b.  false 

    c. Compiler Error

    d. Runtime Error


22.  Which of the following methods is used to obtain a substring with specified begin and end indices? 

    a.  substring() 

    b.  getSubstring() 

    c.  extract() 

    d.  slice() 


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


    String str = "Hello";

    System.out.println(str.indexOf("l", 3));

       

    a.  2 

    b.  3 

    c.  -1 

    d.  4 


24.  Which method is used to convert a string to lowercase and uppercase simultaneously in Java? 

    a.  toCase() 

    b.  caseChange() 

    c.  toLowerCase().toUpperCase() 

    d.  changeCase() 


25.  What is the result of the following expression? 


    "abc".substring(0, 3).equals("abc");

       

    a.  true 

    b.  false 

    c. Compiler Error

    d. Runtime Error






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

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

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

Comments