1. Introduction In this article we will see how to reverse the elements in a primitive array as well as in object array. We will […]
Convert List to array
1. Introduction In this post we will see how to convert List<E> to array in 4 different ways. The following methods acts as a bridge […]
What is Fail-Fast Iterator?
Fail-Fast iterators throw ConcurrentModificationException if the Collection is modified structurally. Fail-Fast iterators fail quickly and cleanly rather than risking the arbitrary non-deterministic behavior at undetermined […]
What is ConcurrentModificationException and why is it useful
ConcurrentModificationException is thrown by methods when they discover concurrent modification of object which such modifications are not permitted. So if the collection is modified structurally […]
Guide to Ints class of Google Guava
1. Overview Ints class in Google Guava provides several static utilities not available in Arrays or Integer class. As primitive types cannot be used as […]
6 different ways to Traverse/Iterate List in Java
1. Introduction In this article, we will see how to traverse the List in a few different ways. This includes traversing using Iterator and without […]
Java 8 Optional Code Smell
Optional<T> class encapsulates the optional value. Optional value means that either the value might or might not be present. It represents immutable container of non-null […]
Do not wrap Collection in Optional
1. Introduction Optional class was introduced in Java 8 to so as to provide a mechanism to represent whether a result is present or not. […]
Return Empty Collections and/or Unmodifiable Collections
1. Introduction In this article we will see about best practices for returning collections. It is common thing to return null from a method whose […]
Count occurrences of substring in input string
1. Introduction In this article we will count occurrences of substring in input string. Below is an exmaple. 2. So, how to write a code […]
Difference between Hashtable and HashMap
Below is the difference between Hashtable and HashMap: In terms of Null keys and Null values Hashtable does not allows null keys or values. If […]
Count frequency of all characters in String
1. Introduction In this String relation interview question, we are supposed to find the frequency of every character in String. For example: Input Output “” […]
Check if two strings are anagram
1. Introduction Two strings are anagram of each other if all the characters of one string matches another string’s characters. 2. Different ways to check […]
3 different ways to find the first non-repeating character in word
1. Introduction In this article we will see how to search for first non-repeating character in the word. 2. Different ways to search for first […]
7 different ways to Traverse Map
1. Introduction In this article, I will show you how to traverse the Map in 7 different ways. Map is an interface that stores key-value […]
Java code to Generate Fibonacci Series.
Embed from Getty Images Fibonacci Series: Fibonacci series is a series of numbers which are built up based on previous numbers. Example: f(1) – The […]
How to use join method of String class?
1. Introduction In this article, we will go through the new methods added in String class in Java 8 under package java.lang. A little about […]