Last active
October 17, 2015 07:51
-
-
Save shekhargulati/3ee0631c904a1a8ca8b6 to your computer and use it in GitHub Desktop.
Java 8 String Sliding Example. Given a String "abcdef" the program should print >> a ab abc abcd abcde abcdef
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import java.util.stream.IntStream; | |
/** | |
* Given a String "abcdef" the program should print | |
* a | |
* ab | |
* abc | |
* abcd | |
* abcde | |
* abcdef | |
*/ | |
public class Sliding { | |
public static void main(String[] args) { | |
final String input = "abcdef"; | |
IntStream.range(0, input.length()) | |
.mapToObj(index -> input.substring(0, index + 1)) | |
.forEach(System.out::println); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment