用 map 输出一定格式的字符串Plain=w=b~|~t=e~|~e=c~|~r=d~|~q=a

输出格式为:Plain=w=b~|~t=e~|~e=c~|~r=d~|~q=a
代码如下:

package ccc;

import java.text.DecimalFormat;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.HashMap;
import java.util.Iterator;
import java.util.Map;
import java.util.Random;

import org.omg.CORBA.Request;

public class Text {

    public static void main(String[] args) {

        Map map = new HashMap();
        map.put("q", "a");
        map.put("w", "b");
        map.put("e", "c");
        map.put("r", "d");
        map.put("t", "e");
        Iterator it = map.keySet().iterator();
        StringBuffer Plain1 = new StringBuffer();
        while(it.hasNext()){
            String key =  (String) it.next();
            Plain1.append(key+"="+map.get(key)) ;
            if(it.hasNext()){
            Plain1.append("~|~");
            }
        }

    }
}

运行结果:Plain=w=b~|~t=e~|~e=c~|~r=d~|~q=a

你可能感兴趣的:(java)