Category: Java


  • This tutorial shows you how to replace multiple consecutive characters with single character. Consider we have an input as: String str = “%%New%%%%”; Here, there are multiple consecutive occurrence of % character and we can replace its each set of consecutive occurrence as shown below: str = str.replaceAll(“(.)\\1+”,”$1″); So, after performing the above replace operation,…

  • Autoboxing is an automatic conversion of a primitive type into its corresponding wrapper class object by the java compiler. For an example, converting an int to an Integer. Consider the following example: int i = 10; Integer j = i; Here, Integer j expects wrapper class of Integer object, but even though if we assign…

  • It is an algorithm that searches for an element one by one in an array, until the target element is found. Consider if X is an element to be searched in an array, then linear search performs the following: Compare X with each element of array one by one If X matches with an element,…

  • It is an algorithm that searches for an element in a sorted array, and it follows a Divide and Conquer algorithmic model. Dictionary is the best example for Binary Search, since the words are in alphabetical order we don’t need to search each page by page for a word. Just, we will compare the word…

  • In java, join() methods allows one thread to wait for the complete execution of other thread. Consider there are two threads T1 & T2, currently thread T1 is executing, and we invoked join() method on T2 then execution of thread T1 is paused and waits for the completion of execution of Thread T2 and then…