• 08 August

    Fibonacci series program in java

    If you want to practice data structure and algorithm programs, you can go through 100+ java coding interview questions. Fibonacci series is numerical series in which next number is sum of previous two numbers. For example : 0, 1, 1, 2, 3, 5, 8, 13, 21, 34, 55 etc. There are two ways to print Fibonacci […]

  • 06 August

    How to remove duplicates from ArrayList in java

    In this post, we will see how to remove duplicate elements from ArrayList in java. There are many ways to do it. Some of them are: Using iterative approach Using HashSet (but does not maintain insertion order) Using LinkedHashMap Program: [crayon-6622135cd97cf656451099/] When you run above program, you will get following output: [crayon-6622135cd97d7120802469/] Please go through java […]

  • 06 August

    Find first non repeated character in a String

    One of the interview question is “How will you find first non repeating character in String.” For example: If input string is “analogy”,  then program should return ‘n’ If input string is “easiest”, then program should return ‘a’ First approach: We will use [LinkedHashMap](https://java2blog.com/linkedhashmap-in-java-with-example/ “LinkedHashMap”) to find first non repeating character in String. Algorithm: Get […]

  • 03 August

    Find all substrings of a String in java

    In this post, we will see java program to find all substrings of a String. For example: If input is “abb”  then output should be “a”, “b”,”b”, “ab”, “bb”, “abb” We will use String class’s subString method to find all subString Program: [crayon-6622135cdad38448436497/] When you run above program, you will get following output: [crayon-6622135cdad41318415137/] Above […]

  • 02 August

    How to find length of string in java without using length() method

    One of the interview question is “How to find length of string in java without using length() method.” There are many ways to find length of String.  Some of them are : Using toCharArray is simplest solution. Using toCharArray Logic Convert string to char array using toCharArray method Iterate over char array and incrementing length […]

  • 01 August

    Java program to check Armstrong number

    Armstrong number is a 3 digit number which is equal to sum of cube of its digits. For example: 371,153 In this post,  we will see how to check for Armstrong number in java. [crayon-6622135cdcb97765291903/] When you run above program, you will get following output. [crayon-6622135cdcba0268612191/] Please go through Frequently asked java interview Programs for more such […]

  • 01 August

    Java program to reverse a String

    In this post,  we will see java program to reverse a String. There are many ways to do reverse a String in java, some of them are: Using for loop Declare empty String reverse. This will contain our final reversed string. Iterate over array using for loop from last index to 0th index Add character […]

  • 01 August

    How to swap two numbers without using temporary variables in java

    In this post, we will see how to swap two numbers without using temporary variables. There are three ways to do it. Java program: [crayon-6622135cdfd2d492911408/] When you run above program, you will get following output: [crayon-6622135cdfd36575900464/] Third way is fastest of all. Please go through Interview programs in java  for more such programs.

  • 10 July

    wait, notify and notifyAll method in java with example

    You might have noticed Object class has three final method called wait, notify and notifyAll. These methods are used for inter thread communication.  Java 5 has introduced executor framework which takes care of inter thread communication for you and internally uses wait, notify and notifyAll but you still require basic understanding of these methods and […]