Skip to content

Instantly share code, notes, and snippets.

Avatar

Kunal sethi kunals201

View GitHub Profile
@kunals201
kunals201 / WordCounts.java
Created Jan 31, 2018
This program count the number of words
View WordCounts.java
import java.io.FileNotFoundException;
import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.Paths;
import java.util.stream.Stream;
public class WordCount {
public static void main(String[] args) throws FileNotFoundException {
countWords("sample.txt");
}
@kunals201
kunals201 / WordCount.java
Last active Jan 31, 2018
testing the gist for blog
View WordCount.java
import java.io.FileNotFoundException;
import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.Paths;
import java.util.stream.Stream;
public class WordCount {
public static void main(String[] args) throws FileNotFoundException {
countWords("sample.txt");
}
@kunals201
kunals201 / CountWords.java
Created Jan 31, 2018
Number of Words count
View CountWords.java
import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.Paths;
import java.util.stream.Stream;
public class WordCount {
public static void main(String[] args) throws IOException {
countWords("sample.txt");
@kunals201
kunals201 / sample.java
Created Mar 9, 2018
Java9 interface private methods example
View sample.java
interface Util {
default int numberOfStudents() {
return helper();
}
private int helper() {
return 10;
}
View sample1.java
public class Sample {
public static void main(String[] args) {
int _ = 4;
System.out.println(_);
}
}
@kunals201
kunals201 / limit.java
Created Mar 16, 2018
limit method example
View limit.java
public class Limit {
public static void main(String[] args) {
List<Integer> numbers = Arrays.asList(11,22,33,44,55,66,77,88,99);
numbers.stream()
.limit(4)
.forEach(System.out::println);
}
View takewhile.java
public class Sample {
public static void main(String[] args) {
List<Integer> numbers = Arrays.asList(11, 22, 33, 44, 55, 66, 77, 88, 99);
numbers.stream()
.takeWhile(e -> e < 66)
.forEach(System.out::println);
}
@kunals201
kunals201 / SkipExample.java
Created Mar 27, 2018
Skip(count) example
View SkipExample.java
public class SkipExample {
public static void main(String[] args) {
List<Integer> numbers = Arrays.asList(11, 22, 33, 44, 55, 66, 77, 88, 99);
numbers.stream()
.skip(5)
.forEach(System.out::println);
}
@kunals201
kunals201 / DropWhileExample.java
Created Mar 27, 2018
Example of dropWhile method
View DropWhileExample.java
public class DropWhileExample {
public static void main(String[] args) {
List<Integer> numbers = Arrays.asList(11, 22, 33, 44, 55, 66, 77, 88, 99);
numbers.stream()
.dropWhile(e -> e < 55)
.forEach(System.out::println);
}
@kunals201
kunals201 / IntStreamIterateExample.java
Last active Mar 27, 2018
example of IntStream iterate
View IntStreamIterateExample.java
public class IntStreamIterateExample {
public static void main(String[] args) {
IntStream.iterate(0, i -> i<5, i -> i+2 )
.forEach(System.out::println);
}
}