当前位置: 首页 > 工具软件 > ACT-R > 使用案例 >

act_1

诸葛绍元
2023-12-01
package act4_1;

import java.util.List;
import java.util.ArrayList;

public class TestArrayList {
    public static void main(String[] args) {
        List<Integer> list = new ArrayList<>();
        
        list.add(1);
        list.add(2);
        list.add(3);
        list.add(4);
        list.add(5);
        
        System.out.println("size: " + list.size());
        
        System.out.println("Before removing: ");
        TestArrayList.<Integer>printAll(list);
        
        list.remove(Integer.valueOf(3));
        
        System.out.println("After removing: ");
        printAll(list);
        
        System.out.println("Does number 4 exists? " + list.contains(4));
        
        List<Integer> another = new ArrayList<>();
        another.add(6);
        another.add(7);
        another.add(8);
        
        list.addAll(another);
        
        System.out.println("After invoking addAll():");
        printAll(list);
    }
    
    private static <T> void printAll(List<T> list) {
        for (int i = 0; i < list.size(); i++) {
            System.out.println(list.get(i) + " ");
        }
        System.out.println();
    }
}
 类似资料:

相关阅读

相关文章

相关问答