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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T08:39:09+00:00 2026-06-08T08:39:09+00:00

HashSet<String> outScopeActiveRegionCodeSet=new HashSet<String>(); for (String regionCode : outScopeActiveRegionCodeSet) { //code required } Here i

  • 0
HashSet<String> outScopeActiveRegionCodeSet=new HashSet<String>();
for (String regionCode : outScopeActiveRegionCodeSet) {
    //code required
}   

Here i need to create new TransactionLOgDTO objects dynamically insed the loop like below.If there are 3 regioncodes in hashset i need 3 TransactionLOgDTO objects with regionCode appended to name of new object.

TransactionLOgDTO regionCode1DTO=new TransactionLOgDTO(); 

}

I need something like this to be done………………………

for (String regionCode : outScopeActiveRegionCodeSet) { TransactionLOgDTO "regionCode"+DTO=new TransactionLOgDTO(); } 
  • 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-08T08:39:10+00:00Added an answer on June 8, 2026 at 8:39 am

    I would recommend using an ArrayList instead of putting the index in the variable name:

    List<TransactionLOgDTO> regionCodeDTOs = new ArrayList<TransactionLOgDTO>();
    HashSet<String> outScopeActiveRegionCodeSet=new HashSet<String>();
    for (String regionCode : outScopeActiveRegionCodeSet) {
        regionCodeDTOs.add(new TransactionLOgDTO());
    }   
    

    or, since you aren’t using the regionCode String:

    List<TransactionLOgDTO> regionCodeDTOs = new ArrayList<TransactionLOgDTO>();
    HashSet<String> outScopeActiveRegionCodeSet=new HashSet<String>();
    for (int i = 0; i < outScopeActiveRegionCodeSet.size(); i++) {
        regionCodeDTOs.add(new TransactionLOgDTO());
    }
    

    Then you can access them using:

    regionCodeDTOs.get(i);
    

    [EDIT]
    If you want to connect the regionCode to the TransactionLogDTO I would recommend a Map instead:

    Map<String, TransactionLOgDTO> transactionCodeDTOs = new HashMap<String, TransactionLOgDTO>();
    HashSet<String> outScopeActiveRegionCodeSet=new HashSet<String>();
    for (String regionCode : outScopeActiveRegionCodeSet) {
        transactionCodeDTOs.put(regionCode, new TransactionLOgDTO());
    }
    

    which are retrieved like:

    transactionCodeDTOs.get(regionCode);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I need to create a Set with initial values. Set<String> h = new HashSet<String>();
Let's say I have this code in Java: HashSet<String> wordSet = new HashSet<String>(); String
I have this code private static Set<String> myField; static { myField = new HashSet<String>();
Need example how to create new local database and a connection string, if possible
I have a HashSet<string> DirectoryHolding = new HashSet<string>(); How do I say I want
Consider the following declaration as part of SomeClass private Set<String> blah = new HashSet<String>();
My model: public class Father { Set<Son> sons = new HashSet<Son>(); String name =
Set<String> tempSet = new HashSet<String>(); for (Map.Entry<String, String> entry : map.entrySet()) { String orginalKeys
I'm using a few functions like ICollection<ICache> caches = new HashSet<ICache>(); ICollection<T> Matches<T>(string dependentVariableName)
WebService.asmx.cs [WebMethod] public HashSet<callInfo> getCalls(string Date, string techID) { HashSet<callInfo> list = new HashSet<callInfo>();

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.