The Difference Between Collection.stream().forEach() and Collection.forEach() 1. Introduction There are several options to iterate over a collection in Java. In this short tutorial, we’ll look at two similar looking approaches — Collection.stream().forEach() and Collection.forEach(). In most cases, both will yield the same results, however, there are some subtle differences we’ll… Continue Reading java-collection-stream-foreach

Java ‘private’ Access Modifier 1. Overview In the Java programming language, fields, constructors, methods, and classes can be marked with access modifiers. In this tutorial, we’ll talk about the private access modifier in Java. 2. The Keyword The private access modifier is important because it allows encapsulation and information hiding, which… Continue Reading java-private-keyword

Java – Random Long, Float, Integer and Double This quick tutorial will illustrate how to generate a long first using plain Java and using the Apache Commons Math library. This article is part of the “Java – Back to Basic” series here on Baeldung. 1. Generate an Unbounded Long Let’s… Continue Reading java-generate-random-long-float-integer-double