Print Consecutive Occurrences of Each Character in String Java

Posted on

Problem Statement: Write a program to print consecutive occurrences of each character in a given string.

Test case 1:
Input : affffssdaaag
Output: a1f4s2d1a3g1

Test case 2:
Input: affffssdaaa
Output: a1f4s2d1a3

Test case 3:
Input: aaa
Output: a3 Read the rest of this entry »

Count Occurrences of Character in a String Java

Posted on Updated on

Problem Statement: Write a program to count occurrence of each character in a given string.

Test case 1:
Input : aabacghc
Output: a3b1c2g1h1

Test case 2:
Input: aaabbcccc
Output: a3b2c4 Read the rest of this entry »

HashMap vs ConcurrentHashMap

Posted on Updated on

ConcurrentHashMap was introduce with JDK1.5 release to replace legacy class Hashtable. In multithreaded environment ConcurrentHashMap performs better as compared to Hashtable and Synchronized Map as well. All methods of Hashtable are synchronized which makes them quite slow due to contention if a number of thread increases. While ConcurrentHashMap is specially designed for concurrent uses which by default allows 16 threads to simultaneously read and write from map without any external synchronization. Read the rest of this entry »

ArrayList vs Vector

Posted on Updated on

Vector is legacy class which is available with Java before collection framework comes into picture while ArrayList was introduce with collection framework. There are some basic differences between ArrayList and Vector as well as few similarities. It is very common to ask question around ArrayList and Vector in interviews. Also if we know the differences and similarities between ArrayList and Vector, it will be easier for us to select one of these while writing our code. Read the rest of this entry »