`我想知道是否有人可以帮助我解决这个问题或建议一种不同的方法来解决这个问题。我正在使用 selenium webdriver,使用 testNG 框架使用 java 进行编码。
基本上,我有一种从 Excel 中提取数据并将其存储为数组列表的方法。例如,我有
此类数据:
Region Text1 Text2 Text3
UK uk_t1 uk_t2 uk_t3
usa usa_t1 usa_t2 usa_t3
russ rus_t1 rus_t2 rus_t3
我的方法从excel中提取所有信息,并根据列名将其存储到arraylist中
示例 -
Arraylist<String>region = new ArrayList<String> ();
Arraylist<String>text1 = new ArrayList<String> ();
Arraylist<String>text2 = new ArrayList<String> ();
Arraylist<String>text3 = new ArrayList<String> ();
ArrayList<String> mydatacells = dataFromExcel(xlspath) // the method on the right is the one with the excel function
String xlspath = "example/mylocation";
int uk = 4; //location of the cell that contains the string uk
int usa = 8; //location of the cell that contains the string usa
int russ = 12; //location of the cell that contains the string russ
然后我编写以下内容来专门提取某个区域的数据
for(uk=4; uk<usa; uk++){
region.add(mydatacells.get(uk));
text1.add(mydatacells.get(uk));
text2.add(mydatacells.get(uk));
text3.add(mydatacells.get(uk));
} //the code assigns the value for uk
我现在的问题是我需要在另一种方法中使用这些值,并且我需要获取所有数据。
有人知道如何做到这一点或更有效的方法吗?
谢谢
最佳答案
将数据放在 map 中更容易 - 我假设第一列的值是唯一的,可以用作键(索引)。然后我会编写一个类来保存单行中的值:
public class Location {
public String region;
public String text1;
public String text2;
public String text3;
}
现在,我会
- 从 Excel 工作表中读取一行
- 创建位置实例
- 将该实例放入 map ,键:location.region,值:location
关于java - 如何从包含数组列表的函数中提取多个字符串值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9685530/