Quantcast
Channel: programcreek.com » Java 8
Browsing latest articles
Browse All 6 View Live

How to Use Optional Type in Java 8 ?

1. Correct Way to Use Optional Consider the following example: List<String> list = new ArrayList<String>(); list.add("java"); list.add("php"); list.add("python"); list.add("perl");...

View Article


Primitive Type Stream Examples

In addition to Stream, java.util.stream package also provide a set of primitive type Streams such as DoubleStream, IntStream and LongStream. The primitive type streams are pretty similar with Stream....

View Article


How to write a counter in Java 8?

Writing a counter in Java can be as simple as 2 lines. In addition to its simplicity, we can also utilize the parallel computation to increase the counter's performance. import...

View Article

Enhanced For-loop vs. forEach() in Java 8

Assuming you have the following list: List<String> list = Arrays.asList("a", "b", "c", "d", "e", "f"); if you want to do something by using each element in a collection, there are two ways: 1)...

View Article

Convert Stream to Array in Java 8

To convert a Stream to an array, there is an overloaded version of toArray() method for Stream objects. The toArray(IntFunction<A[]> generator) method returns an array containing the elements of...

View Article


Default Methods in Java 8 and Multiple Inheritance

From Wiki, Multiple inheritance is a feature of some object-oriented computer programming languages in which an object or class can inherit characteristics and features from more than one parent object...

View Article
Browsing latest articles
Browse All 6 View Live