如何删除05简单字符串的最后两个字符?
简单:
"apple car 05"
Run Code Online (Sandbox Code Playgroud)
码
String[] lineSplitted = line.split(":");
String stopName = lineSplitted[0];
String stop = stopName.substring(0, stopName.length() - 1);
String stopEnd = stopName.substring(0, stop.length() - 1);
Run Code Online (Sandbox Code Playgroud)
拆分前的原始线":"
apple car 04:48 05:18 05:46 06:16 06:46 07:16 07:46 16:46 17:16 17:46 18:16 18:46 19:16
Run Code Online (Sandbox Code Playgroud) 我试图获取466arrayList中的索引minuteList
[288, 318, 346, 376, 406, 436, 466, 1006, 1036, 1066, 1096, 1126, 1156]
Run Code Online (Sandbox Code Playgroud)
但我收到这个错误:
java.lang.IndexOutOfBoundsException: Index: 466, Size: 13
at java.util.ArrayList.rangeCheck(ArrayList.java:635)
at java.util.ArrayList.get(ArrayList.java:411)
at com.pdf.PDF.refill_time_table(PDF.java:155)
at com.pdf.PDF.main(PDF.java:54)
Run Code Online (Sandbox Code Playgroud)
我调试了它,并且minuteList具有上面的值以及变量element具有值466.我该如何解决?
我感谢任何帮助.
码:
Collections.sort(diffArray);
int element = diffArray.get(diffArray.size() - 1).getElement();
int nextElement = diffArray.get(diffArray.size()-1).getNextElement();
//the error occur after this line.
minuteList.get(element);
Run Code Online (Sandbox Code Playgroud) 我正在将我direcList分成两个子列表firstDirec,secondtDirec当New direction发现一个特殊的字符串时.
然后我通过不将它们添加到新的ArrayLists 来过滤列表中的特定字符串timeListFirst and timeListSecond.一切正常firstDirec,并且元素没有添加到timeListFirst,但我secondtDirec在这个位置的列表面临问题:
if (!(mergeLine.equals(otherDirection))
Run Code Online (Sandbox Code Playgroud)
因为在这个位置mergeLine等于"Ravensbusch",所以是 otherDirection.尽管如此,这个字符串正被添加到timeListSecond.有人可以解释我的错误吗?
mergeLine值:

otherDirection值:

for (String keyLine : direcList) {
if (keyLine.startsWith("New direction")) {
int index = direcList.indexOf(keyLine);
// direcArray.remove(index);
List<String> firstDirec = direcList.subList(0, index);
List<String> secondtDirec = direcList.subList(index,
direcList.size() - 1); // This part wih New
// Direction.
ArrayList<String> timeListFirst = new ArrayList<String>();
for (String mergeLine …Run Code Online (Sandbox Code Playgroud)