Skip to content

Instantly share code, notes, and snippets.

View techindepth's full-sized avatar
👋

ANISH ANTONY techindepth

👋
View GitHub Profile
import java.util.stream.*;
class Main {
public static void main(String[] args)
{
// Get the stream
Stream<String> stream
= Stream.of("Geeks", "For",
"Geeks", "A",
var wrapper = new Object(){ int listincrement = 0; };
list.forEach(s -> {
s.setOrdinal(wrapper.ordinal++);
});
AtomicInteger listincrement = new AtomicInteger(0);
list.forEach(s -> {
s.setOrdinal(listincrement.getAndIncrement());
});
List<String> list = Arrays.asList("one", "two", "three");
final int listincrement = 1;
list.forEach(s -> {
listincrement++;//error here
});
List<String> list = Arrays.asList("one", "two", "three");
int listincrement = 1;
list.forEach(s -> {
listincrement++;
});
import java.util.function.Consumer;
public class LambdaScopeTest {
public int x = 0;
class FirstLevel {
public int x = 1;
package com.behindjava.java8;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.function.Function;
public class FunctionTRExample{
public static void main(String args[]){
Function<Employee, String> funcEmpToString= (Employee e)-> {return e.getName();};
List<Employee> employeeList=
Arrays.asList(new Employee("Tom Jones", 45),
@FunctionalInterface
public interface Function<T, R> {
R apply(T t);
default <V> Function<V, R> compose(Function<? super V, ? extends T> before) {
Objects.requireNonNull(before);
return (V v) -> apply(before.apply(v));
}
default <V> Function<T, V> andThen(Function<? super R, ? extends V> after) {
Objects.requireNonNull(after);
return (T t) -> after.apply(apply(t));
package com.behindjava.tutorial;
import java.util.ArrayList;
import java.util.List;
import java.util.stream.Stream;
/**
* @author Anish Antony
*/
public class StreamLimitSkipExample {
String[] names = {"Sam", "Pamela", "Dave", "Pascal", "Erik"};
List<String> nameList =
IntStream.range(0, names.length)
.filter(i -> names[i].length() <= i)
.mapToObj(i -> names[i])
.collect(toList());