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 8320507
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T22:40:23+00:00 2026-06-08T22:40:23+00:00

Ok I am relatively new to Java Programming, but have previous experience in C++.

  • 0

Ok I am relatively new to Java Programming, but have previous experience in C++. I want to search an array for a specific item, but what if there are more than one of the same specific item? Would it be best to use a temporary array to store all found items in the array and return the temporary array?

Note: I’m trying to find the best way of doing this with memory management and speed. And it’s not for Home 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-08T22:40:24+00:00Added an answer on June 8, 2026 at 10:40 pm

    I would use a “ready to use” implementation like a HashMap. You say “search”, so I believe that you have a searchkey (in my proposal the String) under wich you can store your data (for example an Integer).

    Map<String, List<Integer>>  map = new HashMap<String, List<Integer>>(); 
    
        void storeValue(final String key, final Integer value) {
            List<Integer> l = this.map.get(key);
            if (l == null) {
                synchronized (this.map) {
                    if (l == null) {
                        l = new Vector<Integer>();
                        this.map.put(key, l);
                    }
                }
            }
            l.add(value);
        }
    
        List<Integer> searchByKey(final String key) {
            return this.map.get(key);
        }
    

    With this, you can store multiple Integers @ one key. Of course you can store other Object than the Integers.

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

Sidebar

Related Questions

I am relatively new to C++ (previous experience in Python and dabbled in Java)
I'm kind of stumped here. I'm relatively new to Java/Programming in general. I want
I am new to Java programming / Android development - but I have been
I have a .net development background but relatively new to Java world. We have
I'm relatively new to Java and would appreciate any help on this! I have
Like lots of askers on SO, I'm relatively new to java and have attempted
I am relatively new to PHP, but experienced Java programmer in complex enterprise environments
Hi I'm relatively new to Android programming but I would be grateful of some
I'm relatively new to Java and am used to generics in C# so have
I've been programming in Java for a little while now but have never really

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.