gpt4 book ai didi

java - 数组返回 NULL

转载 作者:行者123 更新时间:2023-12-01 18:19:56 26 4
gpt4 key购买 nike

我的一段代码..

package com.xchanging.selenium.utility;

import java.io.IOException;
import java.util.LinkedHashMap;

import org.apache.commons.lang3.ArrayUtils;

public class DataProviderConvertor extends ReadExcel {

public static Object[][] convertData(String sheetName, String testCaseName)
throws IOException {

LinkedHashMap<String, String> table = ReadExcel.getData(sheetName,
testCaseName);
String[] myStringArray = new String[table.size()];
for (String key : table.values()) {
System.out.println("Keyvalues " + key.toString());
String value = key.toString();
ArrayUtils.add(myStringArray, value);
}
System.out.println("1st Index: " myStringArray[0]);
}
}

回来了

Keyvalues Y
Keyvalues ie
Keyvalues QC
Keyvalues Yes
Keyvalues Rework Checklist Comments
Keyvalues Yes
Keyvalues MRI Updated Comments


1st Index: null

我期望这个数组中有 6 个元素,但所有元素都返回 NULL..为什么它没有返回预期值..??

最佳答案

更简单的方法怎么样。

public static Object[][] convertData(String sheetName, String testCaseName)
throws IOException {

LinkedHashMap<String, String> table = ReadExcel.getData(sheetName,
testCaseName);

String[] myStringArray = table.values().toArray( new String[ 0 ] );

System.out.println("1st Index: " + myStringArray[0]);
}

关于java - 数组返回 NULL,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27896644/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com