Passion of IT

Java 1.8 What’s new

Interface with default method


public interface InterfaceDefault {
default void foo(){
System.out.println("Calling A.foo()");
}

 

array parallel sort


int[] myArray=new int [10];
for (int i=0;i<10;i++)
myArray[i]= (int) (Math.random()*100);
Arrays.parallelSort(myArray);

lambda expressions


Runnable java8Runner = () ->{

System.out.println("I am running");
};
java8Runner.run();

new timer type


ZoneId zone = ZoneId.of("Europe/Berlin");
Clock clock = Clock.system(zone);
System.out.print(clock.millis());
LocalDate date = LocalDate.now();
System.out.printf(" %s-%s-%s",
date.getYear(), date.getMonthValue(), date.getDayOfMonth()
);

 

Stream and paralllel stream like groovy closures


Function<Person, Job> mapPersonToJob = new Function<Person, Job>() {
public Job apply(Person person) {
Job job = new Job(person.getPersonId(), person.getJobDescription());
return job;
}
};

java.util.function.Predicate<? super Person> p1 = e -> e.getPersonId() < 6 ;
java.util.function.Predicate<? super Person> p2 = e -> e.getPersonId() < 3 ;
boolean intMap = persons.parallelStream().allMatch(p1);

System.out.println("value:"+intMap);
List <Person> persone = persons.parallelStream().filter(p2).collect(Collectors.toList());

List<Job> jobs = persons.parallelStream().map(mapPersonToJob)
.collect(Collectors.toList());

Job job = mapPersonToJob.apply(person);

 

 

No Comments Yet

Leave a Reply

Your email address will not be published. Required fields are marked *


You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite="
"> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>

Recent Comments

Michele Rizzithe website doesn't exist. Ara you a robot? In any case it's difficult that an automatic system writes a comment here since there are two captchas...
Hello there! This is kind of off topic but I need some guidance from an established blog. Is it very hard to set up your own blog? I'm not very t...
We are a group of volunteers and opening a new scheme in our community. Your web site offered us with valuable information to work on. You've done a...
December 2024
M T W T F S S
« Dec    
 1
2345678
9101112131415
16171819202122
23242526272829
3031  

Login