[85, -86, 13, 2, 99, 99, 99, 99, 98, 98, 99, 99, 99, 99, 20, 85, -86, 13, 2, 99, 99, 99, 99, 99, 99, 99,85, 12, 85, -86, 13, 2, 99]
请教,类似这样的数组如何按照85这个数,拆分为多个新数组
如:
[85, -86, 13, 2, 99, 99, 99, 99, 98, 98, 99, 99, 99, 99, 20]
[85, -86, 13, 2, 99, 99, 99, 99, 99, 99, 99]
[85, 12]
[85, -86, 13, 2, 99]
相关问题
- Delete Messages from a Topic in Apache Kafka
- Jackson Deserialization not calling deserialize on
- How to maintain order of key-value in DataFrame sa
- StackExchange API - Deserialize Date in JSON Respo
- Difference between Types.INTEGER and Types.NULL in
头铁遍历!
public void ArrFun1() {
int[] arr = {85, -86, 13, 2, 99, 99, 99, 99, 98, 98, 99, 99, 99, 99, 20, 85, -86, 13, 2, 99, 99, 99, 99, 99, 99, 99, 85, 12, 85, -86, 13, 2, 99};
String arrStr = Arrays.toString(arr);
System.out.println(arrStr);
List<List<Integer>> list = new ArrayList<List<Integer>>();
List<Integer> temp = new ArrayList<Integer>();
for (int i = 0; i < arr.length; i++) {
if (arr[i] == 85) {
if (temp.size() > 0) {
list.add(new ArrayList<Integer>(temp));
temp.clear();
}
temp.add(arr[i]);
} else {
temp.add(arr[i]);
}
}
list.add(temp);
System.out.println("===============");
for (List item : list) {
System.out.println(Arrays.toString(item.toArray()));
}
}
可