Here you can find the source of toString(HashMap
public static String toString(HashMap<Integer, Long> map)
//package com.java2s; //License from project: BSD License import java.util.HashMap; import java.util.Map.Entry; public class Main { public static String toString(int[] arr) { StringBuilder sb = new StringBuilder("["); for (int i : arr) { sb.append(i + " "); }//w w w .java 2 s . c om sb.append("]"); return sb.toString(); } public static String toString(long[] arr) { StringBuilder sb = new StringBuilder("["); for (long i : arr) { sb.append(i + " "); } sb.append("]"); return sb.toString(); } public static String toString(HashMap<Integer, Long> map) { StringBuilder sb = new StringBuilder("["); for (Entry<Integer, Long> entry : map.entrySet()) { sb.append(entry.getKey() + ":" + entry.getValue() + " "); } sb.append("]"); return sb.toString(); } }