ExceptionMapping 2017-01-03 01:14 采纳率: 0%
浏览 1012

List在debug下重复添加

代码如下:
public static void main(String[] args) throws IOException {

// GetLatAndLngByBaidu b = new GetLatAndLngByBaidu("");
List list = MockUtil.read("D:\Data\gongshang.txt");
// for (String string : list) {
// try {
// System.out.println(string + ":" + b.getByName(string));
// } catch (Exception e) {
// e.printStackTrace();
// }
// }

// 将经度纬度写入到文件里面
File file = new File("D:\Data\aaa.txt");

    OutputStream ot = null;

    Map<String, List> map = new HashMap<String, List>();

    ot = new FileOutputStream(file, true);
    byte[] by = null;
        List<String> listId = null;
        List<String> listNa = null;
        List<String> listlatlng = null;
    for (int i = 0; i < list.size(); i++) {
        String string = list.get(i);
        string = string.replaceAll(",", ":");
        string = string.replaceAll(":", "\r\n:");

        String[] str = string.split(":");



        if (map.get("1") == null) {
            // listId = new Vector<String>();
            listId = new ArrayList<String>();
        }/* else {
            listId = (ArrayList<String>) map.get("1");
        }*/
        listId.add(str[0]);
        map.put("1", listId);
        if (map.get("2") == null) {
            listNa = new ArrayList<String>();
        } /*else {
            listNa = (ArrayList<String>) map.get("2");
        }*/
        listNa.add(str[1]);
        map.put("2", listNa);
        if (map.get("3") == null) {
            listlatlng = new ArrayList<String>();
        } /*else {
            listlatlng = (ArrayList<String>) map.get("3");
        }*/
        listlatlng.add(str[2]);
        map.put("3", listlatlng);

// if (map.get("4") == null) {
// listNa = new ArrayList();
// } else {
// listNa = (ArrayList) map.get("2");
// }
// listNa.add(str[1]);
// map.put("2", listNa);
}
for (int j = 0; j < 3; j++) {
for (String string2 : (ArrayList) map.get((j + 1) + "")) {
by = string2.getBytes();
ot.write(by, 0, by.length);
ot.flush();
}
}
if (ot != null) {
ot.close();
}
}
-------------------------------我是分割线--------------------------------------
上面的代码:是在debug下按F6在listId.add(str[0]);处出现重复添加。循环里的i还是0

  • 写回答

2条回答 默认 最新

  • bdmh 移动开发领域优质创作者 2017-01-03 01:26
    关注

    你调试一下,看看string的值是不是每次都一样

    评论

报告相同问题?

悬赏问题

  • ¥15 C++使用Gunplot
  • ¥15 这个电路是如何实现路灯控制器的,原理是什么,怎么求解灯亮起后熄灭的时间如图?
  • ¥15 matlab数字图像处理频率域滤波
  • ¥15 在abaqus做了二维正交切削模型,给刀具添加了超声振动条件后输出切削力为什么比普通切削增大这么多
  • ¥15 ELGamal和paillier计算效率谁快?
  • ¥15 file converter 转换格式失败 报错 Error marking filters as finished,如何解决?
  • ¥15 Arcgis相交分析无法绘制一个或多个图形
  • ¥15 关于#r语言#的问题:差异分析前数据准备,报错Error in data[, sampleName1] : subscript out of bounds请问怎么解决呀以下是全部代码:
  • ¥15 seatunnel-web使用SQL组件时候后台报错,无法找到表格
  • ¥15 fpga自动售货机数码管(相关搜索:数字时钟)