How to add my array data to my list in java


I have the below code.

List<WebElement> rowItems = driver.findElements(By.xpath("//div[@class='su-table su-table-alternate']//tr"));
List<WebElement> coloumnItems = driver
        .findElements(By.xpath("//div[@class='su-table su-table-alternate']//tr//td"));
String[] coloumnList = new String[coloumnItems.size() / rowItems.size()];
List<ArrayList<String>> gridData = new ArrayList<ArrayList<String>>();
int x = 0;
for (int i = 1; i < rowItems.size(); i++) {
    for (int j = 4; j < coloumnList.length; j++) {
        coloumnList[j] = coloumnItems.get(i).getText();
        // gridData.addAll(coloumnList[j]);
    gridData.Add(new ArrayList<String>(columnList));

I need to add my data in columnList to gridData.

gridData.Add(new ArrayList<String>(columnList)); throwing an error


You can replace it with the following code.

gridData.add(new ArrayList<>(Arrays.asList(columnList)));

Answered By – LUJ

This Answer collected from stackoverflow, is licensed under cc by-sa 2.5 , cc by-sa 3.0 and cc by-sa 4.0

Leave a Reply

(*) Required, Your email will not be published