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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T14:49:59+00:00 2026-06-13T14:49:59+00:00

Whats the quickest way to put a set into a map? public class mySet<T>

  • 0

Whats the quickest way to put a set into a map?

public class mySet<T> 
{
    private Map<T, Integer> map;

    public mySet(Set<T> set) 
    {
        Object[] array = set.toArray();

        for(int i =0; i< array.length; i++)
        {
            T v = (T)array[i];
            map.put(v, 1);
        }
    }
}

Right now, I just converted set into an array and loop through the array and putting them in one by one. Is there any better way to do this?

  • 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-13T14:50:00+00:00Added an answer on June 13, 2026 at 2:50 pm

    One options would be this:

    for (T value : set) {
      map.put(value, 1);
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Whats the easiest and quickest way to loop through an array of numbers and
whats the quickest way to generate an XmlDocument object from a file. Im working
What is the quickest way to jump to a particular symbol/selector/class in Xcode? (I'm
If you had an array of Strings, what is the quickest way to sort
Exploring a new data set: What is the easiest, quickest way to visualise many
What's the quickest way to remove an element from a Map by value in
Whats the quickest way to unmark all the marked items in VC++ 6.0 Ver?
What's the quickest way to get an array of colors in python? Something I
What is the quickest way to set your list view items so that when
What is the quickest way to read a text file into a string variable?

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.