「已注销」 2016-07-18 07:17 采纳率: 0%
浏览 1202

JAVA比较两个字符串是否相等上的一些问题

File file = new File(path);
try {
InputStreamReader read = new InputStreamReader(new FileInputStream(file));
BufferedReader bufferedReader = new BufferedReader(read);
String lineTXT = null;
String[] s3 = null;
while ((lineTXT = bufferedReader.readLine()) != null) {
System.out.println(lineTXT);
s3 = lineTXT.split(",");
}
for (int i = 0; i < s3.length; i++) {
int count = i + 1;
if (s3[i] != s2[i]) {
{
System.out.println("第" + count + "个位置的值不同,值为" + s3[i]);
}
}
}
read.close();
} catch (FileNotFoundException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}

读取了文件的内容放在s3数组里里面然我我定义了一个 String[] s2 = {"124453", "258", "98", "123"};放我比较的时候如果条件写成i < s2.length 就可以正常运行但只能比较出前四项,引文两个数组长度不一样s3数组里面的内容比s数组里面的内容要多,把条件改成i < s2.length,结果比较出前四项之后报错ArrayIndexOutOfBoundsException: length=4; index=4,请问在我代码的基础上要怎么修改才能解决这个问题呢?

简单一句话来说就是两个长度不等的字符串数组找出他们不同的地方 打印出来~要怎么做?怎么修改?

  • 写回答

3条回答 默认 最新

  • threenewbee 2016-07-18 07:18
    关注

    你下标越界了。这个可以用dp解决

    评论

报告相同问题?

悬赏问题

  • ¥15 素材场景中光线烘焙后灯光失效
  • ¥15 请教一下各位,为什么我这个没有实现模拟点击
  • ¥15 执行 virtuoso 命令后,界面没有,cadence 启动不起来
  • ¥50 comfyui下连接animatediff节点生成视频质量非常差的原因
  • ¥20 有关区间dp的问题求解
  • ¥15 多电路系统共用电源的串扰问题
  • ¥15 slam rangenet++配置
  • ¥15 有没有研究水声通信方面的帮我改俩matlab代码
  • ¥15 ubuntu子系统密码忘记
  • ¥15 保护模式-系统加载-段寄存器