Questions tagged [java-8]

Use this tag for questions specific to Java 8 which is version 8 (internal number 1.8) of the Java platform, released on 18 March 2014. In most cases, you should also specify the java tag.

Java 8 features the most changes ever to be introduced in a new Java version.

The most important change is the support for functional paradigm through lambda expressions and method references, under Project Lambda. This is the driving new feature of Java 8.

Other features include:

  • A new Date & Time API
  • A new Stream API integrated into the Collections API
  • Project Nashorn, a JavaScript runtime which allows developers to embed JavaScript code within applications
  • A standard API for performing Base64 encoding and decoding
  • Stronger integration with JavaFX
  • Annotations on Java types

Although it was initially advertised to be launched in September 2013, the release was pushed to March 2014 due to security issues. The GA release has been available for download from Oracle's download page since 18 March 2014.

More details on how Java 8 continues to evolve can be found on the official website and on the JDK8 mailing list.

Please keep in mind that the General Availability version of Java 8 doesn't run on Windows XP.

Reference Material

##Frequently Asked Questions

23031 questions
17
votes
3 answers

Taglib to display java.time.LocalDate formatted

I would like to display formatted java.time.LocalDate in my JSP. Do you know any taglib to use for this? For java.util.Date we were using <%@ taglib prefix="fmt" uri="http://java.sun.com/jstl/fmt" %>. Does something similar for java.time.LocalDate…
Piotr Pradzynski
  • 4,190
  • 5
  • 23
  • 43
17
votes
4 answers

Remove and collect elements with Java streams

Suppose I have a Collection, and a Predicate that matches elements I'd like to remove from the Collection. But I don't just want to discard them, I want to move the matched elements into a new collection. I'd do something like this in Java…
dimo414
  • 47,227
  • 18
  • 148
  • 244
17
votes
1 answer

Are there any benchmarks comparing Java 8 Streams to Guava Iterables?

I'm happy enough with Guava on Java 8 - are there any performance benefits or pitfalls in migrating to Streams for sequential code?
Duncan McGregor
  • 17,665
  • 12
  • 64
  • 118
17
votes
3 answers

How to paginate a list of objects in Java 8?

Given a java.util.List with n elements and a desired page size m, I want to transform it to a map containing n/m+n%m elements. Each map element shall contain m elements. Here's an example with integers: List list = Arrays.asList(1, 2,…
adragomir
  • 457
  • 4
  • 16
  • 33
17
votes
1 answer

Warning: [overloads] method m1 is potentially ambiguous with method m2

import java.util.function.*; class Test { void test(int foo, Consumer bar) { } void test(long foo, Consumer bar) { } void test(float foo, Consumer bar) { } void test(double foo, Consumer
John Kugelman
  • 349,597
  • 67
  • 533
  • 578
17
votes
2 answers

Bug in java.time.Duration

I need to parse Durations from strings. Java 8 provide a method for that taking the ISO-8601 standard as a basis: Duration.parse("p10d"); // parses as ten days Duration.parse("pt1h"); // parses as one hour As the standard states that "it is…
steffen
  • 16,138
  • 4
  • 42
  • 81
17
votes
1 answer

How to handle upper or lower case in JSR 310?

If a month is in UPPER or lower case, i.e. not Title case, DateTimeFormatter cannot parse the date. Is there a simple way to convert a date to title case, or a way to make the formatter more lenient? for (String date : "15-JAN-12, 15-Jan-12,…
Peter Lawrey
  • 525,659
  • 79
  • 751
  • 1,130
17
votes
6 answers

Is Arrays.stream(array_name).sum() slower than iterative approach?

I was coding a leetcode problem : https://oj.leetcode.com/problems/gas-station/ using Java 8. My solution got TLE when I used Arrays.stream(integer_array).sum() to compute sum while the same solution got accepted using iteration to calculate the sum…
cksharma
  • 313
  • 2
  • 11
17
votes
2 answers

What is the best way to convert a byte array to an IntStream?

Java 8 has java.util.stream.Stream and java.util.stream.IntStream types. java.util.Arrays has a method IntStream is = Arrays.stream(int[]) but no such method to make an IntStream from a byte[], short[] or char[], widening each element to an int. Is…
djb
  • 4,930
  • 1
  • 34
  • 37
17
votes
1 answer

Reference to methods with different parameters in Java8

I'm wondering how does all this stuff with method references and functional interfaces works on lower level. The easiest example is where we have some List List list = new ArrayList<>(); list.add("b"); list.add("a"); list.add("c"): Now we…
swch
  • 1,432
  • 4
  • 21
  • 37
17
votes
1 answer

Java access bean methods with LambdaMetafactory

my question is strongly related to Explicit use of LambdaMetafactory in that thread, some very good examples are provided to use the LambdaMetafactory to access a static method of a class; however, I wonder what is the equivalent code to access a…
Francesco Cina
  • 907
  • 1
  • 11
  • 19
17
votes
3 answers

Arrays.asList vs. Arrays.stream to use forEach()

If you have an Array and you want to use the Java8 forEach() method, which approach is better or more efficient: Arrays.asList(new String[]{"hallo","hi"}).forEach(System.out::println); or Arrays.stream(new…
GedankenNebel
  • 2,437
  • 5
  • 29
  • 39
17
votes
1 answer

What do the constructs \H, \V and \N mean?

The following constructs are not well documented, but they do work as of specific versions of PHP onwards; Which are these versions, what are these constructs and which other implementations support this? \H \V \N This thread is part of The Stack…
Unihedron
  • 10,902
  • 13
  • 62
  • 72
17
votes
1 answer

Call constructor with parameter inside Java stream with lambda

I want to call a constructor for MySortedSet that takes in a Comparator c as a parameter. How can I modify this to do so? public MySortedSet subSet(E fromElement, E toElement) { return list.stream() .filter(x -> (list.indexOf(x)…
Jessica
  • 330
  • 1
  • 2
  • 10
17
votes
1 answer

Java 8, why not a ZonedTime class?

I found that Java 8 doesn't have an equivalent to ZonedDateTime but to work only with Time (a ZonedTime class or something like that). I know they included the OffsetTime class, but it only stores the offset. Storing time zones along with date and…
Juan Lhc
  • 327
  • 3
  • 11
1 2 3
99
100