Author: alegru

In one of the previous examples, we covered how to sort an ArrayList in ascending order. In this post, you will learn how to sort ArrayList in descending order in Java. We will explore the following ways: Using the sort() method Using the Collections.sort() and Collections.reverse() methods Sort ArrayList in descending order in Java using the…

Read More Sort ArrayList in descending order in Java

Want to learn how to count character occurrences in Java String? Below is the program that uses a Map to store chars as keys and the number of occurrences as values. class Test { public static void main(String[] args) { String str = “moiujjmhrqdoasdsooqavvae”; Map<Character, Integer> map = new HashMap<>(); for (int i = 0;…

Read More Count Character occurrences in Java String

In this post, you will learn to check if a String contains only digits in Java. We will cover two methods: Using the Character.isDigit() method Using the Integer.parseInt() method Check if a String contains only digits in Java using the Character.isDigit() method In this example, we use a for loop to iterate over the elements…

Read More Check if a String contains only digits in Java

We often need to compare two ArrayList in Java. In this post, you will learn how to do that in two ways: Using the ArrayList.equals() method Using the CollectionUtils.isEqualCollection() method Compare two ArrayList in Java using the ArrayList.equals() method The ArrayList.equals() method compares two ArrayList. It compares the sizes of the lists, elements equality, and the…

Read More Compare two ArrayList in Java

Jackson is a popular Java library that provides powerful tools for converting JSON objects to Java objects and vice versa. In this tutorial, we will explore the different ways of mapping JSON objects to Java objects using Jackson. We’ll also look at how to handle dynamic JSON objects and cover some useful Jackson annotations that…

Read More Master Mapping JSON Objects to Java Objects with Jackson

In the previous lesson, we covered converting Java Object to JSON. Here, you will learn how to convert JSON to Java Object using the ObjectMapper class from the Jackson library. How to convert JSON to Java Object? We will use the readValue() method from the ObjectMapper class. There are a few overloaded readValue() methods. We will use the one that accepts…

Read More Convert JSON to Java Object

Sometimes we need to consume HTTPS endpoints that do not have valid certificates.  We can do that by configuring the Java HttpClient to accept all SSL certificates, even from an untrusted Certificate Authority. Here you will see how to communicate with HTTPS endpoint that may not have a valid SSL certificate. In the following example,…

Read More Java HttpClient – Accept all SSL Certificates