Java

In one of the previous posts, we covered the conversion of a Decimal to Hexadecimal. Here, you will learn how to convert Hexadecimal to Decimal in Java. We will explore the following ways: Using the parseInt() method Using custom logic Convert Hexadecimal to Decimal in Java using the parseInt() method Integer class has a static…

Read More Convert Hexadecimal to Decimal in Java

There are two ways to convert Decimal to Hexadecimal in Java: Using the toHexString() method  With a custom logic Convert Decimal to Hexadecimal in Java using the toHexString() method The easiest way is to use the ToHexString() static method of the Integer class to get the Hexadecimal String of a Decimal number. Example class Test { public…

Read More Convert Decimal to Hexadecimal in Java

Want to learn how to merge two ArrayLists in Java? In this post, we will cover the following ways: Using the List.addAll() method Using the Java 8 Streams Using the ListUtils.union() method Merge two ArrayLists in Java using the List.addAll() method There is addAll() method from the List interface that appends all of the elements in…

Read More How to merge two ArrayLists in Java?

In this post, you will learn how to Serialize and Deserialize an ArrayList in Java using the FileOutputStream and FileInputStream classes. How to Serialize an ArrayList in Java? Serialization is the process of changing the state of an object into a byte stream. For example, we use it to write some Java objects into a file. In…

Read More Serialize and Deserialize an ArrayList in Java

Need to remove a character from String in Java?  You can do that by converting the String to a StringBuilder class and using the deleteCharAt() method that removes the character at a specified position. Example class Test { public static void main(String[] args) { String str = “Learn Java”; str = new StringBuilder(str).deleteCharAt(5).toString(); System.out.println(str); } }…

Read More Remove a Character from String in Java

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