Found 34484 Articles for Programming

How to Fix java.lang.ClassCastException in TreeSet By Using Custom Comparator in Java?

Shriansh Kumar
Updated on 20-Jul-2023 16:22:44

96 Views

The TreeSet is a generic class of Java Collection Framework that implements the SortedSet Interface. It stores the elements of the set in a tree structure. Furthermore, all the elements are stored in a sorted manner and they must be mutually comparable if we are attempting to add custom class objects otherwise we will encounter a java.lang.ClassCastException. Here, custom class objects mean user-defined objects that are created with the help of a constructor. One way to fix this ClassCastException is by using a custom comparator. Let's discuss it in detail. The general syntax for TreeSet is as ... Read More

How to Get All the Values of the LinkedHashMap in Java?

Shriansh Kumar
Updated on 20-Jul-2023 16:01:51

236 Views

LinkedHashMap is a generic class of Java Collection Framework that implements Map Interface. As the name suggests, it is a sub-class of the HashMap class and uses a doubly LinkedList to store the entries in insertion order. It maintains Key-Value pair of entries. The Key is an object that is used to fetch and receive value associated with it. Hence, we can use this key along with 'get()' method to get all the values from LinkedHashMap. The aim of this article is to explain different ways to print all values of the LinkedHashMap. Java Program to Get all ... Read More

How to Get a Value From LinkedHashMap by Index in Java?

Shriansh Kumar
Updated on 20-Jul-2023 15:59:42

414 Views

LinkedHashMap is a generic class of Java Collection Framework that implements Map Interface. As the name suggests, it is a sub-class of the HashMap class and uses a doubly LinkedList to store the entries in insertion order. However, LinkedHashMap does not do any kind of indexing to store the entries, therefore, it is quite a challenge to get specified values from LinkedHashMap with the help of an index. The aim of this article is to explain how to find a value from LinkedHashMap using the index. Java Program to Get a Value from LinkedHashMap by Index Before jumping ... Read More

How to Find the Minimum or Maximum Element from LinkedHashSet in Java?

Shriansh Kumar
Updated on 20-Jul-2023 15:57:10

72 Views

LinkedHashSet is a class of Java Collection Framework that implements the Set interface and extends the HashSet class. It is a linked list type of collection class. It stores and returns the objects in the order in which they were inserted. Finding maximum and minimum elements from a LinkedHashSet collection is one of the common tasks that are frequently asked in exams and even in job interviews. In this article, we are going to explore a few approaches for performing the given task. Program to get Minimum and Maximum elements from LinkedHashSet To find the maximum ... Read More

Golang Program to Creates Two Channels, One For Even Numbers And Another For Odd Numbers

Akhil Sharma
Updated on 20-Jul-2023 15:43:16

906 Views

In this article, we'll make two channels in Go: one for even numbers and another for odd numbers. We are going to send the even numbers to the even channel and the odd numbers to the odd channel.Here we are going to use two different methods: using creating even and odd channels and Sending Even and Odd Numbers to Channels  along with examples to elaborate the concept. Syntax close(evenChan) This is a built in function call used to close a channel. This make sure that no more value will be sent on the channel, and a send operation on ... Read More

Golang Program to Creates a Buffered Channel of Size 5 And Sends 10 Integers to The Channel Using a Loop

Akhil Sharma
Updated on 20-Jul-2023 15:41:39

91 Views

In this article, we focus on making a buffered channel of size 5 and sending 10 integers to the channel using a loop. The program illustrates how to make and utilize a buffered channel to send large values.Here we are going to use two different methods: by Sending integers to the channel using a loop and by creating a buffered channel along with examples to elaborate the concept. Syntax ch := make(chan int, bufferSize) The Syntax ch := make(chan int, bufferSize) creates a buffered channel ch of type int with a specified buffer size, allowing the sender to send ... Read More

How to find the Entry with largest Value in a Java Map

Shriansh Kumar
Updated on 20-Jul-2023 15:51:32

1K+ Views

In Java, Map is an object that stores its element in key-value pairs. The Key is an object that is used to fetch and receive value associated with it. The keys must be unique, but the values associated with them may be duplicated depending on the type of Map class we use. There are several approaches to find an entry with the largest key in Java map and these approaches also depend on the type of Map class we are working with. In this article, we will discuss how to find the entry with largest key in HashMap ... Read More

Golang Program to Get Details About the Car Using Its Number Plate and Engine Number

Akhil Sharma
Updated on 20-Jul-2023 15:40:19

65 Views

In this article, the Golang program is designed to recover details of  a car utilizing its number plate and engine number. It allows users to input the car's data and bring important details such as owner name, registration details, and contact data. By giving  inputs, clients can rapidly get the data they require about a particular car.Here we are going to use three different methods: GetCarDetailsByPlateAndEngine, using validateinput  and using the retrievecardetails function along with examples to elaborate the concept. Syntax func GetCarDetailsByPlateAndEngine(plateNumber string, engineNumber string) (*CarDetails, error) the GetCarDetailsByPlateAndEngine function takes two string parameters (plateNumber and engineNumber), and ... Read More

Golang Program to Get Details About the Car Owner

Akhil Sharma
Updated on 20-Jul-2023 15:39:26

37 Views

In this article, we point to get details about the owner of a car. The program will ask the user to input the car enlistment number, and it'll recover the related information, such as the owner's title, address, and contact data. This program can be valuable in scenarios where car ownership data has to be rapidly accessed.Here we are going to use four different methods:PromptUserInput(), ValidateInput(registrationNumber string) bool, RetrieveOwnerDetails(registrationNumber string) (string, string, string), DisplayOwnerDetails(name, address, contact string) along with examples to elaborate the concept. Syntax func PromptUserInput() string The Syntax func PromptUserInput() string defines a function named PromptUserInput that ... Read More

Golang Program to Create a Slice of Person Structs Called People with at Least Two Elements

Akhil Sharma
Updated on 20-Jul-2023 15:37:05

105 Views

In this article, we are going to explore how to create a Go program that involves a slice of Person structs named People. The slice will contain a minimum of two elements, representing individuals with their respective names and addresses. By exploring the concept of slices and their usage in Go, we will learn how to effectively manage collections of data and perform operations on them. Let's dive in and explore how to work with slices in Go to handle a group of Person structs.Here we are going to use two different methods: using literal initialization and using the append ... Read More

Advertisements