如何从ArrayList中删除不需要的元素?

use*_*005 -2 java arraylist

我有一个数组列表wilth值

ArrayList<String> HexValues = new ArrayList<String>();

    HexValues.add("a");
    HexValues.add("b");
    HexValues.add("f");
    HexValues.add("1");
    HexValues.add("4");
    HexValues.add("0");
    HexValues.add("31");
    HexValues.add("32");
    HexValues.add("37");
    System.out.println("The content of HexValues is: " + HexValues);


    int start = HexValues.lastIndexOf("f");

    if (start != -1) {
        List<String> HexValuesEnd = HexValues.subList(start, HexValues.size());


        System.out.println("The content of HexValuesEnd before leaving is: " + HexValuesEnd);
        if (HexValuesEnd.size() > 0) {               

            HexValuesEnd.remove(1);
            HexValuesEnd.remove(2);
            HexValuesEnd.remove(3);
            System.out.println("The content of HexValuesEnd after removing values at indexes 1 ,2,3: " + HexValuesEnd);
        }
    }
Run Code Online (Sandbox Code Playgroud)

输出是

The content of HexValues is: [a, b, f, 1, 4, 0, 31, 32, 37]
The content of HexValuesEnd  before leaving is: [f, 1, 4, 0, 31, 32, 37]
The content of HexValuesEnd after removing values at indexes 1 ,2,3: [f, 4, 31, 37]
Run Code Online (Sandbox Code Playgroud)

但是第二个数组列表中的预期值应该是

"The content of HexValuesEnd after removing values at indexes 1 ,2,3: " [f,31,32,37]
Run Code Online (Sandbox Code Playgroud)

我哪里错了以获得预期的结果..

小智 5

当您删除其中一个值时,其后的值将被移动以填补间隙.

你的意思是

remove(1);
remove(1);
remove(1);
Run Code Online (Sandbox Code Playgroud)