import java.util.ArrayList;
import java.util.Iterator;


public class app {
public static void main(String[] args) {
ArrayList list=new ArrayList<>();
for(int i=1;i<=100;i++){
list.add(i);
}
Iterator it=list.iterator();
int j=0;
while(it.hasNext()){
j++;
System.out.print(" "+it.next());
if(j%10==0) 
System.out.println();

}
try {
System.out.println("索引50"+list.get(50));
System.out.println("索引102"+list.get(102));

} catch (Exception e) {
// TODO: handle exception
System.out.println("越界异常");
}

}
}使用ArrayList集合,对其添加100个不同的元素

相关文章:

  • 2022-12-23
  • 2021-08-08
  • 2021-08-08
  • 2022-12-23
  • 2022-12-23
  • 2021-04-07
  • 2022-12-23
  • 2022-12-23
猜你喜欢
  • 2021-08-08
  • 2021-04-02
  • 2021-12-30
  • 2021-12-03
  • 2022-12-23
  • 2022-12-23
  • 2021-06-29
相关资源
相似解决方案