Krantik Chavan has Published 278 Articles

Java program to sort string stream with reversed comparator

Krantik Chavan

Krantik Chavan

Updated on 23-Nov-2024 03:58:06

602 Views

In this article, we will learn how to sort a stream of strings using a reversed comparator in Java. Java 8 introduced the Stream API, which allows powerful operations like sorting using custom comparators. Java Comparator A Comparator is a functional interface in Java that defines custom sorting logic. It ... Read More

Java program to get the number of minutes in this duration

Krantik Chavan

Krantik Chavan

Updated on 18-Nov-2024 22:30:42

340 Views

In this article, we calculate the number of minutes in a given duration using Java. The Duration class can perform time-based calculations like hours, minutes, days, etc.. and easily convert between these units. Using the toMinutes() method you will be able to get the number of minutes from a given ... Read More

Java program to create duration from seconds

Krantik Chavan

Krantik Chavan

Updated on 15-Nov-2024 18:43:20

168 Views

In this article, we will learn how to create a Duration object in Java based on different time units like days, hours, milliseconds, and minutes, and then convert them into seconds. The Duration class in Java is part of the java.time package and is used to represent a duration of ... Read More

Java program to disable the first item on a JComboBox

Krantik Chavan

Krantik Chavan

Updated on 14-Nov-2024 17:40:11

983 Views

In this article, we will learn to disable the first item on a JComboBox using Java. This setup is useful for applications where you want to show a placeholder as the first item and prevent it from being chosen, so users must select a valid option. We will be using ... Read More

Java program to display a webpage in JEditorPane

Krantik Chavan

Krantik Chavan

Updated on 13-Nov-2024 12:20:34

742 Views

In this article, we will learn how to display a webpage in JEditorPane using Java. The program will load a specified webpage, and display it within a GUI window. If the connection to the webpage fails, a message will appear indicating the connection issue. This setup can be useful for ... Read More

Java program to fill elements in a long array

Krantik Chavan

Krantik Chavan

Updated on 05-Nov-2024 22:03:17

535 Views

In this article, we will learn how to fill elements in a long array in Java using the Arrays.fill() method. This method allows us to assign a specific long value to all elements of the array. The Arrays.fill() function is a simple way to initialize or overwrite the values in ... Read More

Java program to sort a list placing nulls in the end

Krantik Chavan

Krantik Chavan

Updated on 30-Oct-2024 18:44:59

694 Views

In this article, we will learn how to sort lists containing null values in Java and ensure these nulls are kept at the bottom while upper elements remain in order. This can be done using Comparator.nullsLast, which sorts the non-null elements and places all null elements at last. Problem Statement ... Read More

Java program to get the reverse of an Integer array with Lambda expressions

Krantik Chavan

Krantik Chavan

Updated on 29-Oct-2024 18:51:17

736 Views

In this article, we will learn to get the reverse of an Integer array with Lambda expressions in Java. By utilizing the Arrays.sort() method along with a custom comparator defined as a lambda expression, we can efficiently reorder the elements of the array in descending order. Lambda expressions are a concise ... Read More

Java program to get date for all the days of the current week

Krantik Chavan

Krantik Chavan

Updated on 18-Oct-2024 11:57:36

989 Views

In this article, we will learn to get date for all the days of the current week using Java. We will use the java.time package to get the current date and calculate the dates for the rest of the week based on the current day.  Steps to get date for all ... Read More

Java program to select all the items in a JList

Krantik Chavan

Krantik Chavan

Updated on 10-Oct-2024 11:35:06

784 Views

In this article, we will learn how to select all the items in a JList in Java. The program creates a simple graphical user interface with a list of sports. It uses the setSelectionInterval() method to select all items in the list. This ensures that from the first item to ... Read More

1 2 3 4 5 ... 28 Next
Advertisements