Skip to content

Instantly share code, notes, and snippets.

View kunals201's full-sized avatar

Kunal sethi kunals201

View GitHub Profile
@kunals201
kunals201 / WordCounts.java
Created January 31, 2018 05:19
This program count the number of words
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 January 31, 2018 05:37
testing the gist for blog
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 January 31, 2018 05:40
Number of Words count
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 March 9, 2018 07:28
Java9 interface private methods example
interface Util {
default int numberOfStudents() {
return helper();
}
private int helper() {
return 10;
}
@kunals201
kunals201 / sample1.java
Created March 9, 2018 08:21
No _ example
public class Sample {
public static void main(String[] args) {
int _ = 4;
System.out.println(_);
}
}
@kunals201
kunals201 / limit.java
Created March 16, 2018 10:55
limit method example
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);
}
@kunals201
kunals201 / takewhile.java
Created March 27, 2018 06:57
takeWhile Example
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 March 27, 2018 08:30
Skip(count) example
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 March 27, 2018 08:37
Example of dropWhile method
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 March 27, 2018 11:10
example of IntStream iterate
public class IntStreamIterateExample {
public static void main(String[] args) {
IntStream.iterate(0, i -> i<5, i -> i+2 )
.forEach(System.out::println);
}
}