循环生成arraylist
时间: 2024-05-19 12:15:07 浏览: 57
Python for循环生成列表的实例
Sure, I can help you with that! To loop through and generate an ArrayList in Java, you can use a for loop and the add() method of the ArrayList. Here's an example:
ArrayList<Integer> list = new ArrayList<>();
for (int i = 0; i < 10; i++) {
list.add(i);
}
This code creates a new ArrayList of integers, then loops through 10 times, adding each number to the list. You can replace the Integer type with any other data type you need for your list.
Do you need any more help or information on this topic?
阅读全文