Search for an element in a list, and if it is not found search in another list

I’m making this app where there are three lists. The user inputs two strings, and the app should now see if the two strings are in the same list. If so it should tell the user that they are in the same list and print the index of both. Otherwise it should tell the user in which list string one is and its index inside that list, and the same for string two.

List<String> list1 = Arrays.asList("apples", "oranges");
List<String> list2 = Arrays.asList("tomato", "potato");
List<String> list3 = Arrays.asList("meat", "tuna");

Scanner in = new Scanner(System.in);
String str1 = in.nextLine();
String str2 = in.nextLine();
in.close();

if(list1.contains(str1)) System.out.println("in list1");
else if(list2.contains(str1)) System.out.println("in list2");
else if(list3.contains(str1)) System.out.println("in list3");
else if(list1.contains(str2)) System.out.println("in list1");
else if(list2.contains(str2)) System.out.println("in list2");
else if(list3.contains(str2)) System.out.println("in list3");
else System.out.println("Not found");

Is there any way to make this code better, or do I just have to keep writing if conditions for all the cases I have?

Try with Map

Here is code:

   List<String> list1 = Arrays.asList("apples", "oranges");
    List<String> list2 = Arrays.asList("tomato", "potato");
    List<String> list3 = Arrays.asList("meat", "tuna");

    Scanner in = new Scanner(System.in);
    String str1 = in.nextLine();
    String str2 = in.nextLine();

    Map<String,List<String>> lists = new HashMap<>();
    lists.put("list1",list1);
    lists.put("list2",list2);
    lists.put("list3",list3);

    boolean found = false;
    for(Map.Entry<String, List<String>> entry : lists.entrySet()) {
        if(entry.getValue().contains(str1) && entry.getValue().contains(str2)) {
            found = true;
            System.out.println(new StringBuilder()
            .append("str1 found at index:")
            .append(entry.getValue().indexOf(str1))
            .append(", str2 found at index:")
            .append(entry.getValue().indexOf(str2))
            .append(" in list ")
            .append(entry.getKey()).toString());
        }
    }
    if(!found) {
        System.out.println("Not Found");
    }

You can do it per list. Look if both stringS are contained and return yes for that case. But you must store the position while traversing the list, so you can return its index. I would look in each of the list.

List<List<String> listOfLists = new ArrayList<List<String>();
// add all lists
listofLists.add(list1);
listofLists.add(list2);
listofLists.add(list3);

for (List l : listOfLists){
  int index1 = -1;
  int index2 = -1;
     for (String s : l){
         index++;
       if (s.equalsIgnoreCase(str1)){
         index1= index;
       }
       if (s.equalsIgnoreCase(str1)){
        index2= index;
       }
       if (index1 > -1 && index2 > -1){
         log.info("found both strings at" + index1 + " and " + index2);
       } else {
         log.info("did not found both input strings in a single list");
       }
  }
}
        List<String> list1 = Arrays.asList("apples", "oranges");
        List<String> list2 = Arrays.asList("tomato", "potato");
        List<String> list3 = Arrays.asList("meat", "tuna");

        Scanner in = new Scanner(System.in);
        String str1 = in.nextLine();
        String str2 = in.nextLine();
        System.out.println(str1+(list1.contains(str1)? " in list1":list2.contains(str1)? " in list2":list3.contains(str1)?" in list3":" not found"));
        System.out.println(str2+(list1.contains(str2)? " in list1":list2.contains(str2)? " in list2":list3.contains(str2)?" in list3":" not found"));

EDIT:

    public static void main(String[] args){
        List<String> list1 = Arrays.asList("apples", "oranges");
        List<String> list2 = Arrays.asList("tomato", "potato");
        List<String> list3 = Arrays.asList("meat", "tuna");

        Scanner in = new Scanner(System.in);
        String str1 = in.nextLine();
        String str2 = in.nextLine();
        System.out.println(searchInLists(str1,list1,list2,list3));
        System.out.println(searchInLists(str2,list1,list2,list3));
    }        

    private static String searchInLists(String strToSearch, List<String> ...lists) {
        for(int i = 0; i<lists.length; i++){
            if(lists[i].contains(strToSearch))
                return "in list"+ (i+1) +" at index "+ lists[i].indexOf(strToSearch);                    
        }
       return "not found"; 
    }