B

Bhagwan Das • 4.44K Points
Extraordinary

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

  • (A) abc
  • (B) bc
  • (C) bcd
  • (D) bcd D. abcd
  • Correct Answer - Option(B)
  • Views: 15
  • Filed under category JAVA

Explanation by: Bhagwan Das
substring() method has two variants and returns a new string that is a substring of this string. The substring begins with the character at the specified index and extends to the end of this string or upto endIndex - 1 if second argument is given.

You must be Logged in to update hint/solution

Discusssion

Login to discuss.


Question analytics