Skip to content

Instantly share code, notes, and snippets.

Avatar

Kunal sethi kunals201

View GitHub Profile
@kunals201
kunals201 / Test.java
Last active May 1, 2018
NoDefFoundError problem last class
View Test.java
import pack2.Demo2;
class Test {
public static void main(String[] args) {
System.out.println("Test class main");
Demo2 obj = new Demo2();
obj.test2();
}
}
@kunals201
kunals201 / Demo2.java
Last active May 1, 2018
NoDefFoundErrorProblem
View Demo2.java
package pack2;
import pack1.Demo1;
public class Demo2 {
public void test2()
{
System.out.println("pack2.Demo2 method");
Demo1 obj = new Demo1();
obj.test();
}
View Demo1.java
package pack1;
public class Demo1
{
public void test()
{
System.out.println("pack1.test");
}
}
@kunals201
kunals201 / IfPresentOrElseExample.java
Created Mar 29, 2018
Imperative style example of ifPresent
View IfPresentOrElseExample.java
public class IfPresentOrElseExample {
public static void main(String[] args) {
List<Integer> numbers = Arrays.asList(10, 20, 30, 40, 50, 60, 70, 80, 90);
Optional<Integer> first = numbers.stream().filter(a -> a > 500).findFirst();
if (first.isPresent()) {
System.out.println(first.get());
View IfPresentExample.java
public class IfPresentExample {
public static void main(String[] args) {
List<Integer> numbers = Arrays.asList(10, 20, 30, 40, 50, 60, 70, 80, 90);
Optional<Integer> first = numbers.stream().filter(a -> a > 500).findFirst();
@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);
}
}
@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 / 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);
}
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 / 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);
}