Skip to content

Instantly share code, notes, and snippets.

@shekhargulati
Last active October 17, 2015 07:51
Show Gist options
  • Save shekhargulati/3ee0631c904a1a8ca8b6 to your computer and use it in GitHub Desktop.
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
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