[Java] List replaces the element at the specified position

The method used by List to replace the element at the specified position is the list.set() method:

 List<String> list = new ArrayList<>();
    list.add("1");
    list.add("2");
    list.add("3");
    Log.e("-------原来的list:", String.valueOf(list));
    list.set(1, "5");
    Log.e("-------把下标1更为5后的list:", String.valueOf(list));

Print result:
insert image description here

Reference link: https://blog.csdn.net/qq_33210042/article/details/110289220

Guess you like

Origin blog.csdn.net/m0_46459413/article/details/130576975