Java HashMap to String toString(HashMap map)

Here you can find the source of toString(HashMap map)

Description

to String

License

BSD License

Declaration

public static String toString(HashMap<Integer, Long> map) 

Method Source Code

//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();
    }
}

Related

  1. toStringArray(HashMap syms)
  2. toStringLong(HashMap map)