Learnitweb

Author: Editorial Team

  • Count duplicate elements in ArrayList in Java

    Problem statement For a given list of elements (String elements in our example), the task is to find which elements are duplicate and the number of times the element appears in the list. List “one”, “two”, “three”, “one”, “three”, “four”, “five”, “six”, “one”, “nine”, “six” Output nine : 1six : 2four : 1one : 3five…

  • Object cloning in Java

    1. Introduction While writing programs sometimes there is a need to create a copy of the object, or we can say need to clone an object. The process of creating the clone is defined by the object itself. In this tutorial, we’ll discuss two main aspects to cloning in Java: The intention of cloning an…

  • What is the difference between Object.entries, Object.keys and Object.values methods?

    This is a popular JavaScript interview question to test knowledge about the Object methods. We’ll discuss all these three methods with an example. 1. Object.entries() The Object.entries() method returns an array of given object’s own enumberable [key, value] pairs. The order of the array returned by Object.entries() is same as that provided by a for…in…

  • Fork/Join framework in Java

    1. Introduction In this tutorial, we’ll discuss fork/join framework which is an implementation of ExecutorService interface. The computer systems in present time have multiple cores. A better concurrent programming approach is to use all the computation power of all cores. The fork/join framework enables to use processing power of all available cores. The fork/join framework…

  • Mapping enums in Hibernate

    1. Introduction In this tutorial, we’ll discuss mapping and persisting enums in Hibernate. An enum declaration looks like the following: Each enum constant has an ordinal which represents the sequence in the enum declaration, where the initial constant is assigned an ordinal of 0. For example, ON has ordinal value 0, OFF as 1 and…

  • WeakSet in JavaScript

    1. Introduction A WeakSet is a collection of unique objects and references to objects in a WeakSet are held weakly. The term weakly here means that if no other references to an object stored in WeakSet exist, those objects can be garbage collected. WeakSet can contain only objects. Since objects of WeakSet are held weakly…

  • Stack in Java

    1. Introduction Stack is a last-in-first-out (LIFO) stack of objects. Stack class is a part of collection framework. Elements can in inserted and retrieved at only one end of the Stack. Stack in Java is represented by java.util.Stack class. The java.util.Stack class extends java.util.Vector. Stack implements following interfaces: A stack of plates in a cupboard…

  • SOAP vs REST web services

    1. Introduction REST and SOAP are 2 popular approaches to create web services. Both enable you to define how to build application programming interfaces (APIs), which allow data to be communicated between web applications. Representational state transfer (REST) is a set of architectural principles. Simple object access protocol (SOAP) is a protocol maintained by the…

  • Remove a key value pair from HashMap while Iterating over it

    1. Introduction While programming you may come across a requirement when you want to remove a key value pair while iterating over a HashMap. The requirement is to search a key in HashMap and if found, remove the key value pair. The way you may think of is to iterate over the HashMap and compare…

  • Spring @Primary annotation

    1. Introduction In this quick tutorial, we’ll discuss Spring’s @Primary annotation. The @Primary annotation indicates that a bean should be given preference when multiple candidates are qualified to autowire a single-valued dependency. If there is exactly one bean annotated with @Primary among the candidates, it will be used for autowiring. This annotation may be used…