Link to home
Start Free TrialLog in
Avatar of Nika Gudge
Nika GudgeFlag for United States of America

asked on

How do i add the matched element from one array into another array

String searchCriteria = request.getSearchCriteria();

Product product1 = new Product();
            Product product2 = new Product();
ArrayList<Product> products = new ArrayList<Product>();
            products.add(product1);
            products.add(product2);
            for (int i=0; i<=products.size(); i++){
                  if (products.contains(searchCriteria)){
                        ArrayList<Product> SelectProducts = new ArrayList<SDProduct>();
                        ----- I'm trying to add the products.contains(searchCriteria) into selectProducts--------------
                  }
                  }
            }
            SearchProductResult res = new SearchProductResult(SelectProducts, searchCriteria, showResult);
            return res;
SOLUTION
Avatar of chaitu chaitu
chaitu chaitu
Flag of India image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of CEHJ
>>  if (products.contains(searchCriteria)){

will never be true - the type of object in the Collection is Product and the criteria are of type String. You probably need to look at a field of Product
ASKER CERTIFIED SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial