一、ArrayList

  解决了数组的局限性,最常见的容器类,ArrayList容器的容量capacity会随着对象的增加,自动增长。不会出现数组边界的问题。

package collection;
 
import java.util.ArrayList;
 
import charactor.Hero;
 
public class TestCollection {
    @SuppressWarnings("rawtypes")
    public static void main(String[] args) {
        //容器类ArrayList,用于存放对象
        ArrayList heros = new ArrayList();
        heros.add( new Hero("盖伦"));
        System.out.println(heros.size());
         
        //容器的容量"capacity"会随着对象的增加,自动增长
        //只需要不断往容器里增加英雄即可,不用担心会出现数组的边界问题。
        heros.add( new Hero("提莫"));
        System.out.println(heros.size());
         
    }
     
}
View Code

相关文章:

  • 2022-12-23
  • 2021-08-08
  • 2021-07-27
  • 2021-12-03
  • 2021-05-29
  • 2022-12-23
猜你喜欢
  • 2021-08-06
  • 2022-12-23
  • 2021-11-02
  • 2021-05-21
  • 2022-01-22
  • 2021-11-30
相关资源
相似解决方案