Find Nth node/element from the end of a LinkedList in java

You have given a LinkedList (not java.util.LinkedList), and a number N. Write a program to find/print the value at the Nth node from end of a LinkedList in Java. Solution1 (Using length of a LinkedList): 1)      Find the length of linked list. 2)      Print the (length-n+1) th node/element from starting of the linked list.

[…]

How to Inject object reference to bean Example

In this tutorial we will learn how to inject values to bean via beans configuration file (beans.xml) in Spring 4.1. Technologies used in this article : 1. Spring 4.1.1 2. Maven 1.4 3. Eclipse 4.2 4. JDK 1.6 5. Spring IDE 1. Add Spring 4.1 Dependencies to the project Please add the Spring 4.1 dependencies […]

TreeMap in Java

TreeMap (Since Java1.2): Underlying data structure is Red-Black tree. Insertion order is not preserved since objects will be inserted based on some sorting technique. If you use your own sorting order using Comprator then the key objects need not be Homogenous and Comparable. No restriction on Values. They can be heterogeneous and non-comparable. Duplicate keys […]

Difference between HashMap and WeakHashMap in Java

It is exactly same as HashMap except the below difference. HashMap object is not eligible for Garbage collector even though it does not have any external references if it associated with HashMap. Key of WeakHashMap has weak reference. I.e if the key is garbage collected, and then entry in WeakHashMap object will be deleted automatically. […]

Difference between HashMap and IndentityHashMap

It is exactly same as HashMap except the below difference. HashMap uses equals() method to indentify duplicate keys for object’s content comparision. IndentityHashMap uses ‘==’ operator to identify duplicate keys. Example :  In this example we are creating HashMap and IndentityHashMap objects and inserting integer values.  

 Output:

HashMap uses equals method for […]

setter method example in spring

In this tutorial we will learn how to inject values to bean via beans configuration file (beans.xml) in Spring 4.1. Technologies used in this article : 1. Spring 4.1.1 2. Maven 1.4 3. Eclipse 4.2 4. JDK 1.6 5. Spring IDE 1. Add Spring 4.1 Dependencies to the project Please add the Spring 4.1 dependencies […]

HashMap example with hashCode and equals method in Java

In this tutorial, we will see the importance of hashCode and equals method while writing code by using HashMap. We will see first what the default behaviour of these methods and later will see how to override these methods. Both hashCode() and equals() method are defined in Java.lang.Object class. hashCode () : public navtive int […]

How HashMap works internally in Java

This question is asking in most of the java interviews. Let’s see the story of HashMap. How HashMap works in Java?   It works based on hashing. Hashing is nothing but, Creating and Assigning a unique code to the object. There is a method called “hash (int h) “in HashMap class to do this. From Java […]