How to call one constructor from the other constructor ?

With in the same class if we want to call one constructor from other we use this() method. Based on the number of parameters we pass appropriate this() method is called.

Restrictions for using this method :

  1. this must be the first statement in the constructor
  2. we cannot use two this() methods in

    Read More

How to reverse Singly Linked List?

Output:
Adding: 3
Adding: 32
Adding: 54
Adding:
89 3 32 54 89
reversing the linked list
89 54 32 3

Read More

Find out middle index where sum of both ends are equal

You are given an array of numbers. Find out the array index or position
where sum of numbers preceeding the index is equals to sum of numbers
succeeding the index.

Read More

Write a java program to reverse a string?

1) Using StringBuffer class

In this method, we use reverse() method of StringBuffer class to reverse the string. Here is the code snippet to reverse the string using reverse() method of StringBuffer class.

2) Using iterative method

In this method, first we convert given string to char array using charArray() method. And then we iterate that

Read More

What are static blocks and static initializes in Java ?

Static blocks or static initializes are used to initialize static fields in java. we declare static blocks when we want to initialize static fields in our class. Static blocks gets executed exactly once when the class is loaded. Static blocks are executed even before the constructors are executed.

Example:-

 

Read More

Can we make array volatile in java?

Yes, you can make an array volatile in java but only the reference which is pointing to an array, not the whole array. What I mean, if one thread changes the reference variable to points to another array, that will provide volatile guarantee, but if multiple threads are changing individual

Read More

Find out duplicate number between 1 to N numbers.

Read More

Write a singleton class in Java

Singleton class means you can create only one object for the given class. You can create a singleton class by making its constructor as private, so that you can restrict the creation of the object. Provide a static method to get instance of the object, wherein you can handle the

Read More

Write a java program to remove all white spaces from a string.?

1) Using replaceAll() Method.

In the first method, we use replaceAll() method of String class to remove all white spaces (including tab also) from a string. This is the one of the easiest method to remove all white spaces from a string. This method takes two parameters. One is the string

Read More