set Map Keys To Comma String - Java Collection Framework

Java examples for Collection Framework:Map

Description

set Map Keys To Comma String

Demo Code


//package com.java2s;

import java.util.Iterator;
import java.util.Map;

import java.util.Set;

public class Main {
    public static String setKeysToCommaString(Set s) {

        StringBuffer sb = new StringBuffer();

        Iterator i = s.iterator();

        while (i.hasNext()) {

            Map.Entry o = (Map.Entry) i.next();

            sb.append((String) o.getKey());

            if (i.hasNext()) {
                sb.append(", ");
            }/* w w  w.  j  a va  2 s  .  co  m*/

        }

        return sb.toString();

    }
}

Related Tutorials