在Java中,可以通過以下幾種方法來初始化一個ArrayList:
ArrayList<String> list = new ArrayList<>();
ArrayList<String> list = new ArrayList<>(Arrays.asList("item1", "item2", "item3"));
ArrayList<String> list = new ArrayList<>();
Collections.addAll(list, "item1", "item2", "item3");
ArrayList<String> list = new ArrayList<>(List.of("item1", "item2", "item3"));