list对象转数组

2024-10-09 11:05:06 浏览数 (3)

list对象转数组

代码语言:javascript复制
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");
        }
    }
}

0 人点赞