首页 > 其他分享 >list对象转数组

list对象转数组

时间:2023-11-18 21:00:27浏览次数:33  
标签:String 对象 list timesNoList add str 数组 import

list对象转数组

package com.example.core.mydemo.json5;

import org.apache.commons.collections4.CollectionUtils;

import java.util.ArrayList;
import java.util.List;

/**
 * list对象转数组
 */
public class ArrayTest {
    public static void main(String[] args) {

        List<String> timesNoList = new ArrayList<>();
        timesNoList.add("AAA");
        timesNoList.add("BBB");
        timesNoList.add("CCC");

        if(CollectionUtils.isNotEmpty(timesNoList)) {
            String[] str = timesNoList.stream().toArray(String[] :: new);
            for (int i = 0; i < str.length; i++) {
                System.out.println("array = " + str[i]);
            }
        }else{
            System.out.println("bbb");
        }
    }
}

 

标签:String,对象,list,timesNoList,add,str,数组,import
From: https://www.cnblogs.com/oktokeep/p/17841110.html

相关文章