java - Why are these two substring calls equivalent? -



java - Why are these two substring calls equivalent? -

i'm doing coding question in java , solution works i've seen different solution else posted on blog bit shorter don't understand why works.

the question is:

given non-empty string , int n, homecoming new string char @ index n has been removed. value of n valid index of char in original string (i.e. n in range 0..str.length()-1 inclusive).

my code (which works in conditions):

public string missingchar(string str, int n) { homecoming str.substring(0,n) + str.substring(n+1,str.length()); }

the other code works is:

public string missingchar(string str, int n) { homecoming str.substring(0, n) + str.substring(n + 1); }

the difference right @ end of sec line. question why str.substring(n+1) produce same result str.substring(n+1,str.length())?

the substring() method has 2 variants:

public string substring(int beginindex)

or

public string substring(int beginindex, int endindex)

the substring begins character @ specified beginindex , extends end of string or endindex - 1 if sec argument given.

java substring

Comments

Popular posts from this blog

Delphi change the assembly code of a running process -

json - Hibernate and Jackson (java.lang.IllegalStateException: Cannot call sendError() after the response has been committed) -

C++ 11 "class" keyword -