集册 Java实例教程 将LinkedHashSet的所有元素复制到对象数组

将LinkedHashSet的所有元素复制到对象数组

欢马劈雪     最近更新时间:2020-01-02 10:19:05

378
提示:您可在线编辑运行本教程的实例 - 运行实例,去试试!
将LinkedHashSet的所有元素复制到对象数组

 
 /* from 
 n  o  w  j  a  v  a . c o m*/

import java.util.LinkedHashSet;

 

public class Main {

 

  public static void main(String[] args) {

    LinkedHashSet lhashSet = new LinkedHashSet();

   

    //add elements to LinkedHashSet object

    lhashSet.add(new Integer("1"));

    lhashSet.add(new Integer("2"));

    lhashSet.add(new Integer("3"));

   

    Object[] objArray = lhashSet.toArray();

   

    //display contents of Object array

    System.out.println("LinkedHashSet elements are copied into an Array. Now Array Contains..");

    
展开阅读全文