Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9177197
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T17:16:16+00:00 2026-06-17T17:16:16+00:00

My Arraylist contains 9 persons. Each person has a name value of type String,

  • 0

My Arraylist contains 9 persons. Each person has a name value of type String, an age value of type int and a value of type Enum (TV, SMARTPHONE, CAR). I must create implement a method that will find the name according to the product name.
If arrayListName contains SMARTPHONE, return all names with a smartphone.

public void showByProduct(Product SMARTPHONE) {



    public void showByProductName(Product SMARTPHONE) {

            if (arrayListName.contains(SMARTPHONE))

                System.out.println("found"+nameofowner);
            else {
                System.out.println("not found");
            }
        }
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-17T17:16:17+00:00Added an answer on June 17, 2026 at 5:16 pm

    You would need to iterate over your List, and for each Person, check if it’s product field has the value of the one that you passed in the method.

    Additionally, you would need to have one more List local to your method, in which you would add the Person which matches the Product Name, and then at the end return that List.

    public List<Person> showByProductName(Product product) {
    
        List<Person> localList = new ArrayList<Person>();
    
        for (Person person: persons) {   // persons is the original List.
            if (person.getProduct() == product) {
                localList.add(person);
            }
        }
    
        return localList;
    }
    

    And the place where you call this method, store the return value in a List reference: –

    List<Person> result = showByProductName(Product.SMARTPHONE);
    System.out.println(result);
    

    Note that, you can compare two enum values using ==. As an enum is a singleton.

    P.S: – Don’t have your parameter name as SMARTPHONE. It’s an enum value. And also as per Java Naming Convention, variables name should start with lowercase alphabets, and follow camelCasing thereon.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I want to create large string from Arraylist of Strings . The arraylist contains
I want to search for a string in an arraylist. My ArrayList contains: ArrayList
My arraylist contains String array objects. How Can I get all values? My code
The Setup My Java code contains two objects: a Group and a Person. Each
I have an ArrayList which contains data like profId, firstname, lastname, age. Now I
This function returns ArrayList that contains some data from DB: public ArrayList<ArrayList<Object>> executeQuery(String host,
For simplicity, say I have an ArrayList that contains objects of type A, B
I have an arrayList of arrayLists. Each inner arraylist contains some objects with the
statesList is ArrayList that contains String object. String[] states = new String[2]; states[0] =
I have 2 arraylists contained objects like this: 1st arraylist contains string and double

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.