【发布时间】:2021-04-17 18:24:50
【问题描述】:
我有这样的代码:
ans40 必须为 2,但在三星 s7 等某些手机中显示为 3,我该如何解决?
对不起我糟糕的英语。
谢谢
【问题讨论】:
-
问题可能与
split行为在 Java 8 中发生变化有关。更多信息:Why in Java 8 split sometimes removes empty strings at start of result array?(使用类似split("?!^")的东西来获得相同的行为)。但除此之外 (1) 请不要将文本/代码发布为图像/链接 (more info)。使用edit 选项更正您的帖子。 (2) 不要在同一数据上多次调用split("")。而是存储结果数组并在需要时重用它,例如String[] arr = str.split(""); //then you can use arr[0], arr[1]。 -
(3) 要访问字符串中的所有字符,您根本不需要拆分它。只需致电
yourString.charAt(index)就像char ch0 = anskey.charAt(0);。 -
感谢您帮助我,并抱歉发布图片而不是实际文本。很感激。
标签: java string android-studio split