Java containsAll从多维数组返回错误的索引

Java containsAll从多维数组返回错误的索引,java,arraylist,Java,Arraylist,当我提出这个问题时,我一直在测试我的班级。我什么都试过了,但似乎找不到解决办法。这是我的伪代码: String[] pastaRecipe = {a, b, c, d, e}; String[] saladRecipe = {f, g, h, i, j}; String[][] finalRecipes = {pastaRecipe, saladRecipe}; String[] testInput = {a, b, c, d, e}; if (pastaRecipe contans

当我提出这个问题时,我一直在测试我的班级。我什么都试过了,但似乎找不到解决办法。这是我的
伪代码:

String[] pastaRecipe = {a, b, c, d, e};
String[] saladRecipe = {f, g, h, i, j};
String[][] finalRecipes = {pastaRecipe, saladRecipe};

String[] testInput = {a, b, c, d, e};

    if (pastaRecipe contansAll testInput) then
        print You coulds cook a pasta
    end
以下是我的实现:

公共类RecipeTest(){
公共静态void main(字符串[]args){
试一试{
ArrayList结果=新建ArrayList();
串[]牛排={“猪肉”、“大蒜”、“干月桂叶”、“醋”、“酱油”、“全胡椒玉米”、“盐”};
串[]猪肉串={“猪肉”、“四季豆”、“醋”、“酱油”、“全胡椒玉米”、“盐”};
字符串[][]finalRecipes={porkSteak,porkSoup};
字符串[]testInput={“猪肉”、“大蒜”、“干月桂叶”、“醋”、“酱油”、“全胡椒玉米”、“盐”};
对于(int i=0;i
我的输出: 你可以煮盐

预期产出: 你可以做牛排


要使其以最少的工作量工作,您必须创建一个配方名称数组,并使其与
finalRecipes
数组保持同步

String[][] finalRecipes = {porkSteak, porkSoup};
String[] recipeNames = {"Pork Steak", "Pork Soup"};
然后在
if

if (Arrays.asList(testInput).containsAll(Arrays.asList(finalRecipes[i]))) {
    results.add(recipeNames[i]);
}

但是,理想情况下,您希望创建一个
配方
类,该类将包含配料列表及其名称。

您如何期望输出为
猪肉牛排
?您的伪代码也没有多大意义…您的意思是返回数组的名称,
猪肉牛排
还是..?您的示例代码(除此之外,它不会编译,因为您的
try
没有
catch
子句)返回给我
你可以烹饪大蒜
是的,我想返回菜谱的名称。
包含所有
不返回索引,它返回
布尔值
,基于所讨论的列表是否包含第二个列表中的所有元素。它正在工作。非常感谢您的帮助。很抱歉,标题有误导性。
if (Arrays.asList(testInput).containsAll(Arrays.asList(finalRecipes[i]))) {
    results.add(recipeNames[i]);
}