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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T11:57:57+00:00 2026-06-10T11:57:57+00:00

there are only 3 sets of data in turn1.length,when temp added,there should have three

  • 0

there are only 3 sets of data in turn1.length,when temp added,there should have three different sets of data.But,after i add,even there is 3 group objects,the date in it upexpectedly is the last group of date,all.
I see three different data in debug mode,current attribute will cover the prev data in temp each cycle.

how can i fix it?

  String[] turn1 = idList.split(","); 
  String[] turn2 = labelList.split(","); 
  Attribute attribute = new Attribute(); 
  List<Attribute> Temp = new ArrayList<Attribute>(); 

for(int i=0;i<turn1.length;i++){ 
    long getId; 
    getId = Integer.parseInt(turn1[i]); 
    attribute.setId(getId); 
    attribute.setLabel(turn2[i]); 
    Temp.add(attribute); 
   } 
for(int i=0;i<3;i++) 
System.out.println(Temp.get(i)); 
  • 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-10T11:57:59+00:00Added an answer on June 10, 2026 at 11:57 am

    You are changing the same object in the loop, when you add an object to list, this won’t copy the object, just reference that object, so every element in the list will be pointed to the same original object.

    What you should do is new the Attribute inside the loop.

    String[] turn1 = idList.split(","); 
    String[] turn2 = labelList.split(","); 
    List<Attribute> Temp = new ArrayList<Attribute>(); 
    
    for(int i=0;i<turn1.length;i++){ 
        long getId;
        Attribute attribute = new Attribute(); 
        getId = Integer.parseInt(turn1[i]); 
        attribute.setId(getId); 
        attribute.setLabel(turn2[i]); 
        Temp.add(attribute); 
    } 
    
    for(int i=0;i<3;i++) 
    System.out.println(Temp.get(i)); 
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

There's only room for three lines of text in the interface, but the content
Suppose I have three data sets: X = [1,2,3,4] Y1 = [4,8,12,16] Y2 =
I have 2 sets of data from different systems. About 20,000 records a piece.
I want to have jquery-ui autocomplete automatically select the answer if there is only
I have a master page, there's only one menu item and a contentplaceholder there.
After I made some researches, I found out there is only one way to
I have disable scroll in my app, so there is only scroll from facebook
In sencha touch 2, it appears there are only string, int, float, boolean data
I have two large data sets and I am attempting to reformat the older
I have some large data sets (numeric and textual) and as I'm studying and

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.