java.util.Collections.singletonList() 方法


java.util.Collections.singletonList() 方法

package com.codingdict;

import java.util.*;

public class CollectionsDemo {
   public static void main(String args[]) {

      // create an array of string objs
      String init[] = { "One", "Two", "Three", "One", "Two", "Three" };

      // create one list
      List list = new ArrayList(Arrays.asList(init));

      System.out.println("List value before: "+list);

      // create singleton list
      list = Collections.singletonList("TP");

      System.out.println("List value after: "+list);
   }
}