Java Map to String mapToStr(java.util.Map hm, char sep1, char sep2)

Here you can find the source of mapToStr(java.util.Map hm, char sep1, char sep2)

Description

map To Str

License

Open Source License

Declaration

@SuppressWarnings("unchecked")
    public static String mapToStr(java.util.Map hm, char sep1, char sep2)
    
    

Method Source Code

//package com.java2s;
/*******************************************************************************
 * Copyright (c) 2007, 2009 Oracle. All rights reserved.
 * This program and the accompanying materials are made available under the
 * terms of the Eclipse Public License v1.0, which accompanies this distribution
 * and is available at http://www.eclipse.org/legal/epl-v10.html.
 * /*w  w  w  .  j  a  v a2s . c o m*/
 * Contributors:
 *     Oracle - initial API and implementation
 ******************************************************************************/

public class Main {
    @SuppressWarnings("unchecked")
    public static String mapToStr(java.util.Map hm, char sep1, char sep2)
    //reverse of strToMap
    {
        if (hm == null || hm.isEmpty())
            return null;

        StringBuffer buffer = new StringBuffer();
        java.util.Iterator<java.util.Map.Entry> iter = hm.entrySet().iterator();
        while (iter.hasNext()) {
            java.util.Map.Entry entry = (java.util.Map.Entry) iter.next();
            buffer.append(entry.getKey());
            buffer.append(sep1);
            buffer.append(entry.getValue());
            if (iter.hasNext()) {
                buffer.append(sep2);
            }
        }
        return buffer.toString();
    }
}

Related

  1. mapToStr(Map map)
  2. mapToStr(Map map)
  3. mapToString(final Map m)
  4. mapToString(final Map m)