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

  • SEARCH
  • Home
  • 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 8795719
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T23:27:02+00:00 2026-06-13T23:27:02+00:00

Write a program that reads in a series of first names and eliminates duplicates

  • 0

Write a program that reads in a series of first names and eliminates duplicates by storing them in a Set. Allow the user to search for a first name.

(Trust me, I am not taking any Java classes. So, not my homework).

My issue is to implement this: Allow the user to search for a first name.

Everything else works, just the search feature.

My Code so far….

package com.Sets;

import java.util.Arrays;
import java.util.Collection;
import java.util.Collections;
import java.util.HashSet;
import java.util.List;
import java.util.Scanner;
import java.util.Set;

public class DuplicateElimination {

    public static void main(String[] args) {

        // Write a program thats ask for first names and store it in an array.

        String fName;

        Scanner input = new Scanner(System.in);
        String[] names = new String[10];

        for (int i = 0; i < names.length; i++) {
            System.out.println("Enter First Name: ");
            names[i] = input.nextLine();
        }
        // Printout that array as a list.
        List<String> list = Arrays.asList(names);

        // Initial Array Elements
        System.out.printf("%s ", list);
        System.out.println();

        // Calling removeDuplicates method
        removeDuplicates(list);

    }

    // Make a method called removeDuplicates.
    private static void removeDuplicates(Collection<String> values) {

        // Implement a Hashset in it.
        Set<String> set = new HashSet<String>(values);

        // Printout a non-duplicate list of elements.
        for (String value : set) {
            System.out.printf("%s ", value);
        }

        System.out.println();

    }

    // Make a method to search for a first name.
    public static void searchForName(Collection<String> names) {

        String someName;

        Set<String> set = new HashSet<String>(names);
        Scanner input = new Scanner(System.in);


        for (int i = 0; i <= 10; i++) {
            System.out.println("Search this name: ");
            someName = input.nextLine();
        }

        if (someName ) {

        } else {

        }
    }

}

I don’t feel confident about my searchForName method… can someone give an idea on how I could make this work?

  • 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-13T23:27:03+00:00Added an answer on June 13, 2026 at 11:27 pm

    use set.contains() method to check if a set contains the input string.

       for (int i = 0; i <= 10; i++) {
                System.out.println("Search this name: ");
                someName = input.nextLine();
            }
    
    if(set.contains(someName)) {
    System.out.println("set contains name");
    
    }
    else {
    System.out.println("set doesnt contain this name");
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying to write a program that reads 2 numbers from the user and
I'm trying to write a program that reads 2 numbers from the user and
I'm trying to write a program that reads broadcasted UDP datagrams in linux.I'm a
I am trying to write a Java program that reads an input file consisting
So, I'm trying to write a c program that reads input piped into the
I'm trying to write a basic Erlang program that reads in a file in
I'd like to write a small C program that reads from a file while
Write a program that reads an decimal number between 0 and 2G and displays
I need to write a program that reads from stdin and only writes non-empty
I am required to write a program that reads data into an array of

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.