Java Prototype Pattern tutorial with example

In many cases, creating a new instance is a costly operation. Fortunately, we can copy or clone an instance of an existing one instead of creating from scratch. This approach can be done by using Prototype Pattern, one of Creational Patterns.

[Continue reading…] “Java Prototype Pattern tutorial with example”

How to Sort Java List Objects by Date property with Examples


In the tutorial, We discuss how to Sort Java List Objects by Date property with difference Date types: java.util.Date(using SimpleDateFormat), LocalDate, LocalDateTime. Java provides 2 main approaches for sorting Java List with Comparator:

  • java.util.Collections.sort(List list, Comparator< ? super Customer> c): sorting the specified list according to the order providing by the specified comparator.
  • java.util.Collection.stream().sorted(Comparator< ? super T> comparator): returning a stream consisting of the elements of this stream, sorted according to the provided Comparator.

Let’s do more details with Java syntax examples (Java 7 and Java 8) by descending and ascending sorting order.

[Continue reading…] “How to Sort Java List Objects by Date property with Examples”

How to Sort an Array in Java with Examples


In the tutorial, we will discuss how to Sort an Array with Java in ascending and descending order. java.util.Arrays class provides a lot of Methods to sort an Array with difference types:

  • With Primitives Array, We use the method such as: static void sort(int[] a).
  • With String or Objects Array that implement Comparable, We use method: static void sort(Object[] a).
  • With Custom Object Array that no implement Comparable, We use method: sort(T[] a, Comparator< ? super T> c).

Let’s do more details with Java Array Sorting.

[Continue reading…] “How to Sort an Array in Java with Examples”

Java – Convert Excel File to/from JSON (String/File) – using Apache Poi + Jackson

In the tutorial, Grokonez shows how to convert Excel File to JSON String or JSON File and vice versa with Java language by examples.

[Continue reading…] “Java – Convert Excel File to/from JSON (String/File) – using Apache Poi + Jackson”

Java – Convert CSV File to/from JSON (String/File) – using Commons-CSV + Jackson

In the tutorial, Grokonez shows how to convert CSV File to JSON String or JSON File and vice versa with Java language by examples.

[Continue reading…] “Java – Convert CSV File to/from JSON (String/File) – using Commons-CSV + Jackson”

Java 8 – Sort Map by Value, by Key – Sort Map Custom Object by CompareTo – Descending & Ascending Order

In the tutorial, we show how to sort Java Map by Values, by Keys, and Custom Objects with Descending & Ascending order in Java 8.

[Continue reading…] “Java 8 – Sort Map by Value, by Key – Sort Map Custom Object by CompareTo – Descending & Ascending Order”

How to Install Maven on Windows

In the tutorial, we show how to install Maven on Windows.

Environment:
– Windows 10
– Java 10
– Lastest Maven 3.5.4

Related posts:
Maven Introduction – Part 1
Maven Introduction – Part 2: Maven Repositories and Plugins
Part 3: Maven Dependency Mechanism
Maven Introduction – Part 4: Maven Build LifeCycle
Unit Test – Maven skip test with SpringBoot

[Continue reading…] “How to Install Maven on Windows”

Compress String with Run Length Encoding in Java

In this Java example, we’re gonna know how to compress String in Java with Run Length Encoding (RLE) method.

Related Posts:
Java Regular Expression Overview – Syntax
Java Regular Expression to extract data from a Text
Java Regular Expression to mask information from a Text

[Continue reading…] “Compress String with Run Length Encoding in Java”