0
String s; //enter whatever you want in it for(int i =0; i<s.length(); ++i){ System.out.println(s.substring(0,i)); }
in the above question , what is s.substring(0,i)? what do the two parameters 0 and i do???
5 Antworten
+ 12
@Meharban
:D Sorry, seriously... missing "" at string init.
+ 11
@Meharban
"Meharban Singh"
+ 3
String name='Meharban Singh";
name.substring(4,6);
This would return "rb"
Hence 4,6 means start from index 4 and end when (6-4=2) characters are selected (space is also a character)
Substring is sub-string(subset) of a particular string.
In your.case, you are selecting substring from the first letter until i characters are selected.
NOTE :- In java index starts from 0.
+ 1
@Tashi, xD #SelfPromotion 😂
+ 1
OOPS @Tashi , Thanks ,I changed it.LOL