How to reverse a string in java

In this tutorial we will lean how to reverse a String in Java. There are few ways we can achieve this i.e by using  StringBuffer and StringBuilder class with reverse() method which is useful method to reverse String in Java . Another way is by using for loop we can reverse a String in java. Have […]

Substring in Java

In this tutorial we will lean how substring functionality works from String class in Java.. Let us have a example on substring in Java.  

  OUT PUT:

  Happy to learn String tutorials …. 🙂    

How to remove spaces in between the String in Java

In this tutorial we will learn how to remove spaces in between the String in Java. We can achieve this by using the method “replaceAll”  from String class. Let us have a look in to the below Example…. 🙂 We have a text String like as below                   […]

Constructor Injection example in Spring

In this tutorial we will learn how to inject values to bean via constructor injection 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 like as in […]

Setter method injection tutorial

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 […]

How to reverse a linked list in java using iterative

Write a program to reverse a LinkedList in Java using iterative. Solution: 1) Traverse through the linked list 2) Assign as below in loop      next=prev;      prev=current;      current=next;

 Output:

 

How to find/detect infinite loop of linked list in java

There are multiple solutions to solve this. But we will discuss Floyd’s Cycle-Finding Algorithm. This algorithm also called as “Tortoise and Hare Algorithm”. Solution: 1)      Initialize 2 pointers called fast and slow with header element. Move slow pointer by one element and fast pointer by two elements 2)      If these 2 pointers meet at some […]

Find the Nth node/element from 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 a LinkedList in Java. Solution: 1)      Initialize length to zero 2)      Traverse through the list If length is equal to the passed index, return current element Increment length Assign current element to […]

Find middle node/element of a LinkedList in Java

Write a program to find/print middle element of a Linked list in Java using length of a linked list Solution: 1)      Find the length of linked list. 2)      Print the middle of a linked list at (length/2) th node/element.

 Output:

 

Find middle node/element of a LinkedList in Java in one pass.

Write a program to find/print middle element of a Linked list in Java in one pass. Solution: 1)      Initialize 2 pointers called fast and slow with header element. Move slow pointer by one element and fast pointer by two elements 2)      Once the fast pointer reaches end, then slow pointer will reach middle of a […]