search

Home  >  Q&A  >  body text

java - 请问这个变量如何初始化?

初学java。

 ArrayList<Integer>[] g;
巴扎黑巴扎黑2889 days ago341

reply all(4)I'll reply

  • 巴扎黑

    巴扎黑2017-04-17 17:51:04

    If you want to create an ArrayList array, you can write it like this

    ArrayList<Integer>[] array = new ArrayList[3];
            System.out.println(array.length);

    reply
    0
  • 伊谢尔伦

    伊谢尔伦2017-04-17 17:51:04

    I also suspect[]符号多加了,你应该不会是要一个list的数组。
    那么,ArrayList<Integer> g = new ArrayList<Integer>();如果list的大小确认,可写成:ArrayList<Integer> g = new ArrayList<Integer>(size);Generally, there is no need to specify it. The performance impact is not significant and can be completely ignored.

    reply
    0
  • ringa_lee

    ringa_lee2017-04-17 17:51:04

    Hello! It is recommended to learn more about Java. ArrayList is originally a collection. A collection can be seen as a dynamic array, so there is no need to add [] at the end.

    ArrayList<Integer> g = new ArrayList<Integer>(0);

    reply
    0
  • 天蓬老师

    天蓬老师2017-04-17 17:51:04

    ArrayList<Integer>[] array = new ArrayList<Integer>[Integer.MAX_VALUE];

    reply
    0
  • Cancelreply