A slice is inclusive of the starting index and exclusive of the ending index.
public static String slice(String s) {
return s.substring(0, 2);
}
Function Call | Return Value | |||
---|---|---|---|---|
slice("Car") | → | |||
slice("Truck") | → | |||
slice("556843") | → | |||
slice("Elephant") | → | |||
slice("Roses") | → |
Experiment with this code on Gitpod.io