循环Map,key值用Set接收,最后把循环Set后的StringBuffer 拼接

论坛 期权论坛 脚本     
匿名技术用户   2021-1-1 20:15   11   0
Map<String,Double> excepMap = item.getException();
  StringBuffer permission = new StringBuffer();
  for(int i =0;i<excepMap.size();i++){
   Set<String> exceptionS = excepMap.keySet();
   String[] st = new String[exceptionS.size()];
   int j = 0 ;
   for(String exceptionL : exceptionS){
    st[i++] = exceptionL;
    permission.append(exceptionL+"@");
   }
  }
  System.out.print("看看几个异常:"+permission.toString());

最后的StringBUffer对象拼接后会多出一个“@”符号,下边代码是去掉最后的符号:

String permissionStr = permission.toString();
permissionStr = permissionStr.substring(0,permissionStr.length()-1);//去除多余符号

StringBuilder与 StringBuffer 哪个好点?

分享到 :
0 人收藏
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

积分:7942463
帖子:1588486
精华:0
期权论坛 期权论坛
发布
内容

下载期权论坛手机APP