Java 如何从包含ArrayList的函数中提取多个字符串值
`我想知道是否有人能帮我解决这个问题,或者建议一种不同的解决方法。我正在使用SeleniumWebDriver,使用testNG框架用java编码 基本上,我有一个从excel中提取数据并将其存储为ArrayList的方法。比如说,我有 这类数据:Java 如何从包含ArrayList的函数中提取多个字符串值,java,webdriver,Java,Webdriver,`我想知道是否有人能帮我解决这个问题,或者建议一种不同的解决方法。我正在使用SeleniumWebDriver,使用testNG框架用java编码 基本上,我有一个从excel中提取数据并将其存储为ArrayList的方法。比如说,我有 这类数据: Region Text1 Text2 Text3 UK uk_t1 uk_t2 uk_t3 usa usa_t1 usa_t2 usa_t3 russ rus_t1 ru
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
Arraylistregion=newarraylist();
Arraylisttext1=新的ArrayList();
Arraylisttext2=新的ArrayList();
Arraylisttext3=新的ArrayList();
ArrayList mydatacells=dataFromExcel(xlspath)//右侧的方法是带有excel函数的方法
字符串xlspath=“示例/mylocation”;
int-uk=4//包含字符串uk的单元格的位置
int usa=8//包含字符串usa的单元格的位置
int-russ=12//包含字符串RUS的单元格的位置
然后,我编写以下代码来提取特定区域的数据
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
for(uk=4;uk在映射中更容易获得数据-我假设第一列的值是唯一的,可以用作键(索引)。然后我将编写一个类来保存单行中的值:
public class Location {
public String region;
public String text1;
public String text2;
public String text3;
}
现在,我想
从excel工作表中读取一行
创建位置的实例
将该实例放到地图上,键:location.region,值:location
谢谢。我会尝试一下,看看效果如何。Map Map=dataFromExcel(xlsPath)