java

java

Read json content from a file using GSON in Java

This tutorial will show you how to read JSON content from a file in Java using the GSON library.

Read
java

Java program to sort an array of integers in ascending order

In this Java programming tutorial, we will learn how to sort an array of integers in ascending order. Our program will first take the inputs from the user and create one integer array. Then it will sort the numbers of the array and print it out again to the user.

Read
java

How to remove elements of Java ArrayList using removeIf() method

Normally, for removing an element from an arraylist, we iterate through the list one by one using an iterator, check each element if it satisfy a specific condition and if it does, delete it. But, starting from Java-8, we don't need to write all of these code. Java-8 has introduced one new method removeIt() to remove all elements from a collection that satisfy a condition.

Read
java

Java program to print below and above average marks students

In this Java programming tutorial, we will learn how to find the students who got above or below average marks from a list of students. Mainly, our program will create a list of students with different name and marks for each student. It will then find out the average marks of all of these students. Finally, it will print out the students whose marks is below average and above average.

Read
java

How to convert a boolean to string in Java

In this quick tutorial, we will learn how to convert a boolean value to string in Java. Not only one, we have two different ways to do the conversion. Let's take a look :.

Read
java

How to convert stacktrace to string in Java

Stack Trace helps to find out the root cause of an exception. Sometimes you may want to save the stack-trace in string format for further analysis, like saving it in your database, sending It to your server etc.

Read
java

4 different ways to convert a string to double in Java

Converting a string to double in Java is easier than you think. We have a lot of different approaches to do this conversion. In this tutorial, we will learn four different ways to convert a string to double. We will include different examples for each. Let's have a look :.

Read
java

Java user defined or custom exception example

In java, we have different types of exceptions already available. For example, NullPointerException, ArrayIndexOutOfBoundException , ClassNotFoundException , FileNotFoundException etc. All of these exceptions invokes for specific predefine rules. For example, NullPointerException occurs if we try to do any operation on a null value, ArrayIndexOutOfBoundException occurs if we are trying to access an invalid index of a array etc.

Read
java

Java Example to empty an Arraylist

To remove all elements from an ArrayList in Java, we have two inbuilt methods - clear() and removeAll(). Both methods can remove all elements from an ArrayList. Both method looks same but there is a difference between them. Even both of them performs differently.

Read
java

How to add zeros to the start of a number in Java

In this Java tutorial, we will learn how to modify a number by padding zeros at start. For example, if the number is 123 and if we want to add three zeros to the start of this number, it will become 000123. We will show you two different ways to achieve this in this tutorial :.

Read