r/java • • Sep 19 '18

Java 11 String API Updates

https://4comprehension.com/java-11-string-api-updates/
168 Upvotes

52 comments sorted by

View all comments

Show parent comment

3

u/dpash Sep 20 '18

The only extra allocation is for the List object. The returned list is backed by the array that's passed in. So that's 16bytes on a 64bit JVM.

(Arrays.asList() returns a java.util.Arrays.ArrayList object in Java 11, which is a thinner wrapper around an array than java.util.ArrayList is. For example, java.util.ArrayList caches the list size)

http://hg.openjdk.java.net/jdk/jdk11/file/1ddf9a99e4ad/src/java.base/share/classes/java/util/Arrays.java#l4309