currently working on a project for college. when searching coffee names from the array list , it will only show the first object in the array list but when searching others, it says 'coffee not found' any help would be appreciated

public static void search () {

        if (numberOfCoffees > 0) {

            System.out.println ("search coffee");
            System.out.println ("what are you searching for?");
            String search =  sc.nextLine();

            int i = 0;
            int o = 0;
            String arrayName = coffee[i][0];
            if (arrayName.equals(search)){

                System.out.println("found: " + coffee[i][0] + " £" + coffee[i][1] );

            } else  {

                System.out.println ("coffee not found");

            }

        } else {

            System.out.println("there is  no coffee  in the list");

        }
    }

You need a loop in which you compare the search string with each entry in the array until you find a match, or exit the loop having not found any match

ps. That's an array. An ArrayList is a completely different thing.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.