String string1 = "Hello World"; String substring = string1.substring(0,5);After this code is executed the
substring
variable will contain the string Hello
.
The
substring()
method takes two parameters. The first is the character index
of the first character to be included in the substring. The second is the index of the character
after the last character to be included in the substring. Remember that. The parameters
mean "from - including, to - excluding". This can be a little confusing until you memorize it.@reference_1_jenkov.com
No comments:
Post a Comment