Articles on Trending Technologies

Technical articles with clear explanations and examples

C++ Program to Perform the Shaker Sort

Ravi Ranjan
Ravi Ranjan
Updated on 12-May-2025 2K+ Views

Shaker sort is a variation of bubble sort and is both a stable and comparison based sorting algorithm. The shaker sort is also known as cocktail sort or bidirectional bubble sort as it sorts the array in both directions. In this article, we have an unsorted array. Our task is to implement the shaker sort in C++ to sort the given array. Example The following example sorts the unsorted array using the shaker sort: Input: array = {5, 1, 4, 2, 8, 0, 2} Output: Sorted array = {0, 1, 2, 2, 4, 5, 8} The ...

Read More

C++ Program to Perform Stooge Sort

Ravi Ranjan
Ravi Ranjan
Updated on 12-May-2025 439 Views

Stooge Sort is a recursive sorting algorithm used to sort the given data. The stooge sort divides the array into two overlapping parts, 2/3 each and then sort the array in three steps by sorting first then second and again first part. The worst case time complexity of this algorithm is O(n^2.7095). In this article, we have an unsorted array. Our task is to implement the stooge sort algorithm for sorting the given array in C++. Example Here is an example of sorting the given array using stooge sort: Input: array = {5, 3, 8, 4, 2, 7} ...

Read More

Custom instance creator using Gson in Java?

Aishwarya Naglot
Aishwarya Naglot
Updated on 12-May-2025 2K+ Views

While parsing a JSON String to or from a Java object, by default, Gson tries to create an instance of the Java class by calling the default constructor. In the case of Java, if a class doesn’t contain a default constructor or we want to do some initial configuration while creating Java objects, we need to create and register our own instance creator. Custom Instance Creator Using Gson Custom instance means creating a new instance that is not the default. In this instance, we can add whatever properties we want. There are many libraries that create custom instances. In this ...

Read More

How to deserialize a JSON to Java object using the flexjson in Java?

Aishwarya Naglot
Aishwarya Naglot
Updated on 12-May-2025 5K+ Views

Deserializing a JSON to a Java object means converting a JSON string into a Java object.The deserialize() Method of the Flexjson Library We will be using the Flexjson library to deserialize a JSON to a Java object in Java. The Flexjson library is a lightweight library that is used for serializing as well as deserializing Java objects to and from JSON. A JSONDeserializer is the main class for performing deserialization of JSON to Java objects. We can deserialize a JSON string to a Java object using the deserialize(String json, Class type) method of JSONDeserializer. Syntax of deserialize() Method The syntax of the ...

Read More

How to ignore the null and empty fields using the Jackson library in Java?

Aishwarya Naglot
Aishwarya Naglot
Updated on 12-May-2025 2K+ Views

The Jackson is a library for Java and it has very powerful data binding capabilities and it also provides a framework to serialize custom java objects to JSON and deserialize JSON back to Java object. Ignoring Null and Empty Fields Using Jackson The Jackson library provides @JsonInclude annotation, which controls the serialization of a class as a whole or its individual fields based on their values during serialization. The @JsonInclude annotation contains below two values: Include.NON_NULL: Indicates that only properties with not null values will be included in JSON. Include.NON_EMPTY: Indicates ...

Read More

How can we change a field name in JSON using Jackson in Java?

Aishwarya Naglot
Aishwarya Naglot
Updated on 12-May-2025 5K+ Views

When we have a JSON object and want to change a specific field name for some reason, we can use the Jackson library in Java.The Jackson Annotation @JsonProperty The Jackson Annotation @JsonProperty is used on a property or method during the serialization or deserialization of JSON. It takes an optional 'name' parameter, which is useful in case the property name is different from the key name in JSON. By default, if the key name matches the property name, the value is mapped to the property value. If the key name is different, we can use the @JsonProperty annotation to ...

Read More

How to exclude a field from JSON using @Expose annotation in Java?

Aishwarya Naglot
Aishwarya Naglot
Updated on 12-May-2025 3K+ Views

Sometimes we need to exclude certain fields from the JSON output. For example, if we have a field that contains sensitive information, we may not want to include it in the JSON representation of the object. In such cases, we can use the Expose annotation provided by Gson. The Gson @Expose annotation The Gson @Expose annotation can be used to specify whether a field isto be exposed or not (included or not). The @Expose annotation can take two parameters, and each parameter is a boolean which can take either the value true or false. The two parameters are: ...

Read More

Convert an Iterator to a List in Java

Aishwarya Naglot
Aishwarya Naglot
Updated on 12-May-2025 794 Views

An Iterator is used for cycling through a Collection of objects. Whereas a List is an Interface which is used for storing an ordered collection of elements. Both classes are part of the Java Collections Framework.Converting an Iterator to a List in Java  Sometimes we need to convert an Iterator to a collection. In this article, we will learn how to convert an Iterator to a List in Java using multiple ways. Those are: Using a while loop Using Iterator.forEachRemaining() Using Stream API Let's understand each of them in ...

Read More

Convert an Iterable to Stream in Java

Aishwarya Naglot
Aishwarya Naglot
Updated on 12-May-2025 476 Views

What is an Iterable?Iterable is an Interface that is used for iterating over a Collection of objects. It is part of the Java Collections Framework. The Iterable interface is implemented by all the collection classes in Java. For example, ArrayList, HashSet, etc. The Iterable interface has a method named iterator() which returns an Iterator object.What is a Stream? Stream is an Interface that is used for processing sequences of elements. It is part of the Java Collections Framework. The Stream interface is a newly added abstraction in Java 8. It is mainly used for sequential operations on collections, for example, ...

Read More

Convert an Iterable to Collection in Java

Aishwarya Naglot
Aishwarya Naglot
Updated on 12-May-2025 449 Views

In Java, we can store objects within other objects. A collection is an object that stores other objects. Some examples of collections are ArrayList, HashSet. Iterable is an Interface that is used for iterating over a Collection of objects. It is part of the Java Collections Framework. The Iterable interface is implemented by all the collection classes in Java. The Iterable interface has a method named iterator() which returns an Iterator object. In this article, we will learn how to convert an Iterable to a Collection in Java using multiple ways. Those are - Using for-each ...

Read More
Showing 30931–30940 of 61,297 articles
Advertisements