为了账号安全,请及时绑定邮箱和手机立即绑定

我想对两个列表进行去重处理,但现在发现两个list里的“1”不同。

我想对两个列表进行去重处理,但现在发现两个list里的“1”不同。

HUH函数 2018-07-06 06:22:59
     public static void main(String[] args) throws Exception {         String file1 = "file1.txt";         String file2 = "file2.txt";         ArrayList<String> list1 = addToList(file1);         ArrayList<String> list2 = addToList(file2);         String s1 = list1.get(0);         String s2 = list2.get(1);         if (!s1.equals(s2)){             System.out.println("不同==="+s1+"==="+s2+"===");         }     }     static ArrayList<String> addToList(String file) throws Exception {         ArrayList<String> lines = new ArrayList<>();         BufferedReader br = null;         br = new BufferedReader(new FileReader(file));         String strLine = null;         while ((strLine = br.readLine()) != null){             strLine = strLine.trim();             if ( strLine != ""){                 lines.add(strLine);             }         }         return lines;     }
查看完整描述

1 回答

?
慕村9548890

TA贡献1884条经验 获得超4个赞

我一开始用你的代码测试,没有问题。
所以我认为是有不可见字符在里面导致的,我加了个7f到里面,可以看到如下:

https://img1.sycdn.imooc.com//5b66e9cc0001f5ee01310074.jpg

不同===1===1===


查看完整回答
反对 回复 2018-08-05
  • 1 回答
  • 0 关注
  • 781 浏览

添加回答

举报

0/150
提交
取消
微信客服

购课补贴
联系客服咨询优惠详情

帮助反馈 APP下载

慕课网APP
您的移动学习伙伴

公众号

扫描二维码
关注慕课网微信公众号