Performance improvement of using lambda expressions with new features of Java 8 vs. other possible variants of iterating over ArrayList in Java

Open access

Abstract

A fluent programming is the programming technique where operations return a value that allows the invocation of another operation. With the fluent programming, it is perfectly natural to end up with one huge statement that is the concatenation of as many operations as you like. The Java Development Kit (JDK) streams (added in Java 8) are designed to support fluent programming. Instead of looping over all elements in the sequence repeatedly (once for filter, then again for map, and eventually for toArray), the chain of filtermapper-collector can be applied to each element in just one pass over the sequence. In this context, we often encounter lambda expressions used to create locally defined anonymous functions. They provide a clear and concise way to represent one method interface using an expression. Oracle claims that use of lambda expressions also improve the collection libraries making it easier to iterate through, filter, and extract data from a collection. In addition, new concurrency features improve performance in multicore environments.

There are multiple ways to traverse, iterate, or loop collection in Java. Therefore, to solve one problem, we have several options for solutions that differ by undeniably increasing of the code readability. Searching for answers to the question of whether these new features really bring performance benefits over conventional way, is the subject of this paper.

If the inline PDF is not rendering correctly, you can download the PDF file here.

  • Aggregate Operations. The Java™ Tutorials. 2017. © Oracle. [online]. [cit. 2017-03-10]. Available on internet: ⟨http://docs.oracle.com/javase/tutorial/collections/streams/index.html⟩.

  • API Specification. Java™ Platform Standard Ed. 8. 2017. © Oracle 1993–2017. [online]. [cit. 2017-03-10]. Available on internet: ⟨https://docs.oracle.com/javase/8/docs/api/overview-summary.html⟩.

  • Class ArrayList. Java™ Platform Standard Ed. 8. 2017. © Oracle. [online]. [cit. 2017-03-10]. Available on internet: ⟨https://docs.oracle.com/javase/8/docs/api/java/util/ArrayList.html⟩.

  • Class Colectors. Java™ Platform Standard Ed. 8. 2017. © Oracle. [online]. [cit. 2017-03-10]. Available on internet: ⟨https://docs.oracle.com/javase/8/docs/api/java/util/stream/Collectors.html⟩.

  • Collections. The Java™ Tutorials. 2017. © Oracle. [online]. [cit. 2017-03-10]. Available on internet: ⟨http://docs.oracle.com/javase/tutorial/collections/index.html⟩.

  • Default Methods. The Java™ Tutorials. 2017. © Oracle. [online]. [cit. 2017-03-10]. Available on internet: ⟨https://docs.oracle.com/javase/tutorial/java/IandI/defaultmethods.html⟩.

  • HORSTMANN S. CAY. 2014. Java SE 8 for the Really Impatient. Addison-Wesley Professional 2014. ISBN-13: 978-0-321-92776-7 ISBN-10: 0-321-92776-1. 240 pp.

  • Interface Iterable. Java™ Platform Standard Ed. 8. 2017. © Oracle. [online]. [cit. 2017-03-10]. Available on internet: ⟨https://docs.oracle.com/javase/8/docs/api/java/lang/Iterable.html⟩.

  • Interface Iterator. Java™ Platform Standard Ed. 8. 2017. © Oracle. [online]. [cit. 2017-03-10]. Available on internet: ⟨https://docs.oracle.com/javase/8/docs/api/java/util/Iterator.html⟩.

  • Interface List. Java™ Platform Standard Ed. 8. 2017. © Oracle. [online]. [cit. 2017-03-10]. Available on internet: ⟨https://docs.oracle.com/javase/8/docs/api/java/util/List.html⟩.

  • Interface Stream. Java™ Platform Standard Ed. 8. 2017. © Oracle. [online]. [cit. 2017-03-10]. Available on internet: ⟨https://docs.oracle.com/javase/8/docs/api/java/util/stream/Stream.html⟩.

  • JAVIN P. 2012. Difference between LinkedList vs ArrayList in Java. © 2012–2017. [online]. [cit. 2017-03-10]. Available on internet: ⟨http://javarevisited.blogspot.sk/2012/02/difference-between-linkedlistvs.html⟩.

  • JAVIN P. 2014. 10 Example of Lambda Expressions and Streams in Java 8. © 2012–2017. [online]. [cit. 2017-03-10]. Available on internet: ⟨http://javarevisited.blogspot.sk/2014/02/10-example-of-lambdaexpressions-in-java8.html#axzz4oaVpthXZ⟩.

  • JAVIN P. 2016. How does Enhanced for loop works in Java? © 2012–2017. [online]. [cit. 2017-03-10]. Available on internet: ⟨http://javarevisited.blogspot.sk/2016/02/how-does-enhanced-for-loop-works-injava.html#ixzz4jcEyMSvz⟩.

  • JAVIN P. 2017. Java67: Java Programming tutorials and Interview Questions. © 2012–2017. [online]. [cit. 2017-03-10]. Available on internet: ⟨http://www.java67.com/2012/12/difference-between-array-vsarraylist-java.html#ixzz4i7DJtfrq⟩.

  • KISHORI S. 2014. Beginning Java 8 Language Features: Lambda Expressions Inner Classes Threads I/O Collections and Streams. Apress 2014. ISBN 1430266597 9781430266594. 704 pp.

  • Lambda Expressions. The Java™ Tutorials. 2017. © Oracle. [online]. [cit. 2017-03-10]. Available on internet: ⟨http://docs.oracle.com/javase/tutorial/java/javaOO/lambdaexpressions.html#syntax⟩.

  • LANGER A. and KREFT K. 2013. Lambda Expressions in Java. [online]. [cit. 2017-03-10]. Available on internet: ⟨http://www.angelikalanger.com/Lambdas/Lambdas.pdf⟩.

  • LANGER A. 2015. Java performance tutorial — How fast are the Java 8 streams? [online]. [cit. 2017-03-10]. Available on internet: ⟨https://jaxenter.com/java-performance-tutorial-how-fast-are-the-java-8-streams-118830.html⟩.

  • SCHILDT H. 2014. Java 8 eSampler. Preview exclusive excerpts from brand-new and forthcoming Oracle Press Java JDK 8 books. Oracle Press. © 2014 McGraw-Hill Education. [online]. [cit. 2017-03-10]. © 2010. Available on internet: ⟨http://www.oracle.com/technetwork/java/newtojava/java8book-2172125.pdf⟩.

  • Spring. 2017. Working with Spring Data Repositories. © 2011–2017. [online]. [cit. 2017-03-10]. Available on internet: ⟨https://docs.spring.io/spring-data/data-commons/docs/1.6.1.RELEASE/reference/html/repositories.html⟩.

  • WARD A. DEUGO D. 2015. Performance of Lambda Expressions in Java 8. [online]. [cit. 2017-03-10]. Available on internet: ⟨http://worldcomp-proceedings.com/proc/p2015/SER2509.pdf⟩.

  • WILLIAMS M. and J. Q. NUNEZ 2015. Java SE 8: Lambda Quick Start. © Oracle. [online]. [cit. 2017- 03-10]. Available on internet: ⟨http://www.oracle.com/webfolder/technetwork/tutorials/obe/java/Lambda-QuickStart/index.html⟩.

Search
Journal information
Impact Factor
Mathematical Citation Quotient (MCQ) 2017: 0.06

Metrics
All Time Past Year Past 30 Days
Abstract Views 0 0 0
Full Text Views 1248 1135 29
PDF Downloads 652 605 12