Java中列表数组到数据表的转换

Java中列表数组到数据表的转换,java,cucumber,Java,Cucumber,有人能提出解决方案吗?我试图将列表数组转换为数据表,并将其传递给另一个方法,但它似乎不起作用。我不断得到错误:- cucumber.runtime.CucumberException:表不平衡:应为0列,但找到1列。 解释该问题的示例代码:- public void test(){ List<String> tabs = new ArrayList<String>(); tabs.add("A"); tabs.add("B");

有人能提出解决方案吗?我试图将列表数组转换为数据表,并将其传递给另一个方法,但它似乎不起作用。我不断得到错误:-

cucumber.runtime.CucumberException:表不平衡:应为0列,但找到1列。

解释该问题的示例代码:-

public void test(){

 List<String> tabs = new ArrayList<String>();
        tabs.add("A");
        tabs.add("B");
        tabs.add("C");

        **DataTable allTabs = DataTable.create(tabs);
        receiveData(allTabs);**

}

public void **receiveData(DataTable data){**
 List<List<String>> tabs = tabs.asLists(String.class);
        for (int i = 1; i < tabs.size(); i++) {
            if (tabs.get(i).get(0).contains("A")) {
               System.out.println("Print A");

            }
            else if (tabs.get(i).get(0).contains("B")) {
                System.out.println("Print B");
            }
            else if (tabs.get(i).get(0).contains("C")) {
                    System.out.println("Print C");
            }
    }

*****************End of Issue*************************
公共无效测试(){
列表选项卡=新建ArrayList();
表2.添加(“A”);
加上(B);
表3.添加(“C”);
**DataTable allTabs=DataTable.create(制表符);
接收数据(所有选项卡)**
}
公共无效**接收数据(数据表数据){**
列表选项卡=tabs.asLists(String.class);
对于(int i=1;i
*****2019年12月12日更新:- 以下同事给出的解决方案:-

public void test(){

 List<String> tabs = receiveData("A", "B", "C");

        **DataTable allTabs = DataTable.create(tabs);
        receiveDataTwo(allTabs);**

}

**private List<List<String>> receiveData(String... tabs) {
        return Arrays.stream(tabs)
                .map(ImmutableList::of)
                .collect(Collectors.toList());
    }**

public void **receiveDataTwo(DataTable data){**
 List<List<String>> tabs = tabs.asLists(String.class);
        for (int i = 1; i < tabs.size(); i++) {
            if (tabs.get(i).get(0).contains("A")) {
               System.out.println("Print A");

            }
            else if (tabs.get(i).get(0).contains("B")) {
                System.out.println("Print B");
            }
            else if (tabs.get(i).get(0).contains("C")) {
                System.out.println("Print C");
        }
}*****
公共无效测试(){
列表选项卡=接收数据(“A”、“B”、“C”);
**DataTable allTabs=DataTable.create(制表符);
接收数据2(所有选项卡)**
}
**私有列表接收数据(字符串…选项卡){
返回数组.stream(选项卡)
.map(不可变列表::of)
.collect(Collectors.toList());
}**
公共无效**接收数据二(数据表数据){**
列表选项卡=tabs.asLists(String.class);
对于(int i=1;i
for(inti=1;ii=0
标签的开始是0,或者不是1。< /P>你使用的是哪一个版本的黄瓜?我想让你看看你在这里做了什么。考虑你是从别人的角度看它并告诉我你的想法吗?我已经得到了一个解决方案(你可以看到它在我原来的帖子中更新了)。由一位同事设计的,它是有效的,但如果有更好的,那会很有趣…@GerhardBarnard。我只是想把一个列表数组转换成datatable,就是这样