How does a collection become an array, how does an array become a collection

Set to array

  • Call toArray() static method
  Object[] objects = collection3.toArray();
    for (int i = 0; i < objects.length; i++) {
    
    
        System.out.println(objects[i]);
    }

Array becomes collection

  • Call the static method asList() of the Arrays class
 List strings = Arrays.asList(new String[]{
    
    "AA", "BB", "CC"});

Guess you like

Origin blog.csdn.net/weixin_46351306/article/details/113747513