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;
Java

Avatar of undefined
Last Comment
CEHJ
SOLUTION
Avatar of chaitu chaitu
chaitu chaitu
Flag of India image

Blurred text
THIS SOLUTION IS ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
Avatar of CEHJ
CEHJ
Flag of United Kingdom of Great Britain and Northern Ireland image

>>  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
Avatar of CEHJ
CEHJ
Flag of United Kingdom of Great Britain and Northern Ireland image

Blurred text
THIS SOLUTION IS ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
Java
Java

Java is a platform-independent, object-oriented programming language and run-time environment, designed to have as few implementation dependencies as possible such that developers can write one set of code across all platforms using libraries. Most devices will not run Java natively, and require a run-time component to be installed in order to execute a Java program.

102K
Questions
--
Followers
--
Top Experts
Get a personalized solution from industry experts
Ask the experts
Read over 600 more reviews

TRUSTED BY

IBM logoIntel logoMicrosoft logoUbisoft logoSAP logo
Qualcomm logoCitrix Systems logoWorkday logoErnst & Young logo
High performer badgeUsers love us badge
LinkedIn logoFacebook logoX logoInstagram logoTikTok logoYouTube logo