将数组视为List,List-Array

import java.util.Arrays;
import java.util.LinkedList;

public class ListsToArrays {

public static void main(String[] args) {
    // TODO Auto-generated method stub
    String[] colors = {"black", "blue", "yellow"};
      LinkedList<String> links = new LinkedList<>(Arrays.asList(colors));

      links.addLast("red"); // add as last item
      links.add("pink"); // add to the end
      links.add(3, "green"); // add at 3rd index
      links.addFirst("cyan"); // add as first item      

      // get LinkedList elements as an array     
      colors = links.toArray(new String[links.size()]);

      System.out.println("colors: ");

      for (String color : colors)
         System.out.println(color);
}

}
Console:
colors:
cyan
black
blue
yellow
green
red
pink

©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容