本习题主要用于练习如何使用ArrayList来替换数组。
新建1个ArrayList strList用来存放字符串,然后进行如下操作。
提示:查询Jdk文档中的ArrayList。
注意:请使用System.out.println(strList)输出列表元素。
输入样例:
a1 b1 3b a2 b2 12b c d !!end!!
b1
second
b
输出样例:
[begin, a1, b1, 3b, a2, b2, 12b, c, d, end]
true
2
2
begin
[a1, b1, 3b, a2, b2, 12b, c, d, end]
[a1, second, 3b, a2, b2, 12b, c, d, end]
[3b, b2, 12b]
[a1, second, 3b, a2, b2, 12b, c, d, end]
[],0,true
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Scanner;
public class Main {
public static void main(String[] args) {
ArrayList<String> strList = new ArrayList<>();
Scanner sc = new Scanner(System.in);
while (true) {
//直到输入为!!end!!时,结束输入。
String h = sc.next();
if (!("!!end!!"