Found 7442 Articles for Java

Shuffling Elements of Unordered Collections in Java

Shriansh Kumar
Updated on 01-Sep-2025 12:15:11

1K+ Views

There are two types of Collections in Java. One is ordered and the other one is unordered collection. The ordered collections store their elements in the order in which they are inserted i.e. it maintains the insertion order of elements. Whereas, the unordered collections such as Map and Set do not maintain any order. In this article, we will create an unordered collection and try to shuffle its elements using the inbuilt method Collections.shuffle(). The Collections.shuffle() Method The Collections.shuffle() method is provided by java.util package. It takes a list as an argument and then rearranges the elements randomly. Therefore, before ... Read More

Rules of Downcasting Objects in Java

Shriansh Kumar
Updated on 01-Sep-2025 12:14:35

906 Views

In Java, downcasting is the process of converting an object of parent class to object of child class. We need to perform the conversion explicitly. It is quite similar to what we do in primitive typecasting. In this article, we will learn about downcasting and what are the rules that we must follow to downcast an object in Java. There is one more concept for modifying objects named Upcasting. In this process, the object of sub class gets converted to super class object. It can be done implicitly. Both the concepts, upcasting and downcasting together called object casting. Object Downcasting ... Read More

Searching Elements in Vector Using Index in Java

Shriansh Kumar
Updated on 01-Sep-2025 12:13:21

212 Views

Vectors implement the List interface and are used to create dynamic arrays. The array whose size is not fixed and can grow as per our needs is called as a dynamic array. The vectors are very similar to ArrayList in terms of use and features. In this article, we will learn how we can create a vector and search for a particular element by its index in Java. Let's discuss Vector first. Java Vector Vector is similar to ArrayList in many ways but there exist some differences too. The Vector class is synchronized and several legacy methods are contained in ... Read More

Sort an Array of Triplet using Java Comparable and Comparator

Shriansh Kumar
Updated on 01-Sep-2025 12:16:33

357 Views

In this article, we will create an array of triplet and try to sort them using the Comparable and Comparator interfaces. The term array of triplet means an array having three elements. An Array is a fixed-length linear data structure that stores group of elements with similar datatypes in a sequential manner. Sort an Array of Triplet using Comparator As the name suggests, Comparator is used to compare something. In Java, the Comparator is an interface that can be passed as a parameter to sorting methods like Arrays.sort() or Collections.sort() to sort custom objects. To use it, we need to ... Read More

Sort Java Vector in Descending Order using Comparator

Shriansh Kumar
Updated on 15-May-2023 17:08:52

547 Views

Vectors implement the List interface and are used to create dynamic arrays. The array whose size is not fixed and can grow as per our needs is called as a dynamic array. The Comparator is an interface available in ‘java.util’ package. Sorting means rearranging the elements of a given list or array in ascending or descending order. In this article, we will create a vector and then try to sort its elements in descending order using a comparator. Program to Sort Java Vector in Descending Order Comparator As the name suggests it is used to compare something. In ... Read More

Runtime Type Identification in Java

Shriansh Kumar
Updated on 15-May-2023 16:56:42

957 Views

Runtime Type Identification in short RTTI is a feature that enables retrieval of the type of an object during run time. It is very crucial for polymorphism as in this oops functionality we have to determine which method will get executed. We can also implement it for primitive datatypes like Integers, Doubles and other datatypes. In this article, we will explain the use case of Runtime Type Identification in Java with the help of examples. Program for Runtime Type Identification Let’s discuss a few methods that can help us to identify type of object: instanceOf It is a ... Read More

Sort LinkedHashMap by values using Comparable Interface in Java

Shriansh Kumar
Updated on 15-May-2023 16:53:12

420 Views

LinkedHashMap is a generic class that is used to implement Map Interface. Also, it is a sub class of the HashMap class therefore, it can use all the methods and also perform similar operations that a HashMap class is capable of. Java provides various ways to sort LinkedHashMap, we will learn how to create and sort it by its values using Comparable Interface through this article. Program to sort LinkedHashMap by Values Before jumping to the sorting program directly, let’s take a look at few concepts first − LinkedHashMap As we have discussed earlier the LinkedHashMap class extends ... Read More

Sort LinkedHashMap by Keys in Java

Shriansh Kumar
Updated on 15-May-2023 16:49:47

1K+ Views

LinkedHashMap is a generic class that is used to implement Map Interface. Also, it is a sub class of the HashMap class therefore, it can use all the methods and also perform similar operations that a HashMap class is capable of. Java provides various ways to sort LinkedHashMap, we will learn how to create and sort it by using its keys through this article. Program to sort LinkedHashMap by Keys Before jumping to the sorting program directly, let’s take a look at few concepts first − LinkedHashMap As we have discussed earlier the LinkedHashMap class extends HashMap class ... Read More

Runtime JAR File in Java

Shriansh Kumar
Updated on 15-May-2023 16:48:29

810 Views

The full form of JAR is Java Archive File. Java provides this feature to bundle multiple java program files as well as their corresponding class files into one single unit. Perhaps, it is the only file format that can store audio, video, text files and so forth in one place. In this article, we will discuss how we can create and access a JAR file in Java. Java JAR File The need for data compression was felt to store and transmit large amounts of data without any hassle. For this purpose, a ZIP file was introduced that encouraged Java creators ... Read More

Program to Convert Byte Array to Writer in Java

Shriansh Kumar
Updated on 15-May-2023 16:45:00

363 Views

Byte Array can be said as the combination of byte and array. Byte is the smallest integer type and Array is a linear data structure that is used to store groups of elements of similar datatypes. This article will discuss a program to convert Byte Array to Writer in Java. Let’s understand the term Byte Array and Writer first. Byte Array and Writer Class Byte Array It is a type of array that stores a sequence of data of byte datatype. We will use the ‘getBytes()’ method to convert specified strings into sequences of characters and store them in a ... Read More

Advertisements