Java 8 Stream – Read a file line by line
In Java 8, you can use Files.lines to read file as Stream. A new method lines() has been added since 1.8, it lets BufferedReader returns content as Stream.
Java – Convert String to double
In Java, we can use Double.parseDouble() to convert a String to primitive double, and we can use Double.valueOf() to convert a String to an Double object.
How to format a double in Java
In Java, we can use String.format or DecimalFormat to format a double, both support Locale based formatting.
Java – How to round double / float value to 2 decimal places
There are a few ways to round float or double to 2 decimal places in Java. In short, for monetary calculation, picks BigDecimal; for display purpose, picks DecimalFormat("0.00"). We can…
Java – Display double in 2 decimal places
In Java, there are few ways to display double in 2 decimal places. We can use DecimalFormat("0.00") to ensure the number is round to 2 decimal places. We also can…
How to calculate monetary values in Java
There are many monetary values calculation in the financial or e-commerce application, and there is one question that arises for this – Should we use double or float data type…
Java 8 – How to Sum BigDecimal using Stream?
In Java 8, we can use the Stream.reduce() to sum a list of BigDecimal. Java example to sum a list of BigDecimal values, using a normal for loop and a…
Java 8 Stream findFirst() and findAny()
In Java 8 Stream, the findFirst() returns the first element from a Stream, while findAny() returns any element from a Stream.
Java – How to convert a primitive Array to List
Code snippets to convert a primitive array int to a List. In Java 8, you can use the Stream APIs to do the boxing and conversion. You can’t use the…
How to sort an Array in java
Java example to show the use of Arrays.sort() to sort an Array. The code should be self-explanatory. Output Download Source Code $ git clone https://github.com/favtuts/java-core-tutorials-examples $ cd java-basic/array Reference Arrays…