Frequently Used Methods of Java HashMap

HashMap is very useful when a counter is required.

HashMap<String, Integer> countMap = new HashMap<String, Integer>();
//.... a lot of a's like the following
	countMap.put(a, countMap.get(a)+1);
	countMap.put(a, 1);

Read more

Why String is immutable in Java?

String is immutable in Java. An immutable class is simply a class whose instances cannot be modified. All information in an instance is initialized when the instance is created and the information can not be modified. There are many advantages of immutable classes. This article summarizes why String is designed to be immutable. This post illustrate the immutability concept in the perspective of memory, synchronization and data structures.

Read more

How to Convert Array to ArrayList in Java?

This article analyzes answers for a top-voted questions on Stack Overflow. The person who asked this question got a lot of reputation points, which could grant him permissions to do a lot of things on Stack Overflow. This does not make sense to me, but let’s take a look at the question first.

The question is “how to convert the following array to an ArrayList?”.

Read more

How to format Java Code by using Eclipse JDT?

If you use eclipse, you probably format your code by pressing Ctrl+Shift+F or right clicking Source -> Format very often. This function is also provide in JDT, so you can also format your Java code in Java code.

Finding the correct JDT API for doing this job, however, is not straight-forward. In the following code, you will see one of the classes being used is actually an internal class.

Read more

What can we learn from Java HelloWorld?

This is the program every Java programmer knows. It is simple, but a simple start can lead to deep understanding of more complex concepts. In this post I will explore what can be learned from this simple program. Please leave your comments if hello world means more to you.

public class HelloWorld {
	 * @param args
	public static void main(String[] args) {
		// TODO Auto-generated method stub
		System.out.println("Hello World");

Read more