Introduction A HashSet or any other Set is a collection that doesn’t allow you to add duplicate elements. If you want objects of a class to be stored in a Set, you must override equals() and hashCode() methods. You must…
Author: kart1c
HashMap
Introduction Let’s assume you want a collection where you want to store key/value pairs. To store the key/value pair, pass both key and value and to get a value, provide the key and the collection will give you back the…
equlas, hashCode and toString method
Introduction The Object class defines the equals(), hashCode() and toString() methods. As all the classes are child classes of the Object class, these three methods are available in every Java class. Below is the source code of the Object class.…
LinkedList
LinkedList stores a group of elements and it maintains order of insertion. For LinkedList we don’t specify the size, as we add elements, the size gets bigger automatically. Also LinkedList allows duplicates. This might sound similar to ArrayList. But the…
ArrayList
The Problem An array is an object that is used to store a fixed number of values of similar type. The length of an array is established when it is created. Once created its length can not be changed. The…
Collection
Introduction Java collection represents a group of individual objects that behaves as a single unit. The Java Collections Framework provides a set of interfaces and classes to create those groups. In one situation, you might want a group of objects…
Generics and type safety
The background Before Java 5.0, all the collections (like List, Set etc.) were supposed to hold type Object. So, you can put anything to the collection, but when you get something out of that collection, you will get a reference…
Wrapper Classes, Autoboxing, Unboxing
Wrapper Classes We all know, there are 8 primitive data types supported by java. Sometimes you need to treat those primitives as objects (we will discuss why in a moment). For that reason, java provides wrapper classes for each primitive…
Abstract class, interface & polymorphism
Abstract Class We have already discussed, inheritance is a mechanism by which one object can acquire all the properties and behavior of a parent object. For example, A Mobile super class. Let’s consider, a mobile should be capable of at…
Inheritance
We have discussed briefly about inheritance earlier. Today we will understand the concept in detail. A story Let’s assume you are working as a developer in a mobile company called YouPhone. Your manager asked you to write code for the…