请教如何将HashMap里的数据读出,拼成字符串,如001,002,003 循环取出来。。 int---->string 只要加个引号就OK了 例如:001+“” 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 HashMap是键值存储的 ,根据键取得值 LZ。001 002 003 循环map.keySet()StringWriter sw=new StringWriter();PrintWriter pw=new PrintWriter(sw);pw.printf("%3d",1);Sysout.out.println(sw.toString()); import java.util.*;public class test { public static void main(String[] args){ String str=""; HashMap map=new HashMap(); map.put("one","001" ); map.put("two", "002"); map.put("three", "003"); Collection collect=map.values();//将map中的values取出来,并实现一个Collection接口 Iterator it=collect.iterator();//再用Collection接口的迭代器 while(it.hasNext()){ str+=it.next().toString()+",";//通过迭代器遍历values } str=str.substring(0,str.length()-1);//去掉最后一个逗号 System.out.println(str);//001,002,003 }}是这样吧?输出是"001,002,003" 可以获取到值的inteor来迭代取出然后拼字符串 想实现一个列表显示数据,并在后面添加操作的功能。 SSH2+spring security 求解啊!整合出问题了! 密码验证 equals()方法问题 请教关于return的用法 JMF如何播放其包含以外的格式如:RMVB RM 关于Servlet!!! Hibernate中配置EHCache 变态的问题,到什么程度了,进来就知道了 开源邪说!—— 盲目开源到底是什么?到底伤害着谁? jdom怎么设置字符集的编码,我用jdom输入的xml中的中文全都是乱码呀。 有会用netbeans软件的吗?有人会用它连接sqlite吗?还有往列表框里加图标怎么加,谢谢。 你们现在能访问oracle站点吗?
PrintWriter pw=new PrintWriter(sw);
pw.printf("%3d",1);
Sysout.out.println(sw.toString());
public class test { public static void main(String[] args){
String str="";
HashMap map=new HashMap();
map.put("one","001" );
map.put("two", "002");
map.put("three", "003");
Collection collect=map.values();//将map中的values取出来,并实现一个Collection接口
Iterator it=collect.iterator();//再用Collection接口的迭代器
while(it.hasNext()){
str+=it.next().toString()+",";//通过迭代器遍历values
}
str=str.substring(0,str.length()-1);//去掉最后一个逗号
System.out.println(str);//001,002,003
}}
是这样吧?输出是"001,002,003"