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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T17:38:56+00:00 2026-06-14T17:38:56+00:00

I want to add every element of an arraylist into a single object (Which

  • 0

I want to add every element of an arraylist into a single object (Which has a generic base type T )

Im trying to do this but when i print out the final output which is the object, i only have the last element of the arraylist printed.

So its itterating through every element but stores and prints the last.

Any suggestions?

  • 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-14T17:38:58+00:00Added an answer on June 14, 2026 at 5:38 pm

    Assuming that your T is not an aggregate type, it is not possible to put many objects into one.

    If your T is a collection and you want to collapse the collections, you can iterate each of the source collections and add each value to the target collection.

    However, what it sounds to me like you are really after is nice printable view of the object. If this is for debugging, I recommend finding one of the many JSON support libraries, and printing the JSON conversion of the object, which wlll be readable. I rolled my own, since I had to support Domino API types, so I cannot recommend one.

    I have been doing far, far too much C# lately, and cannot think in fluent Java right now, but something close to this (in spirit at least, if not syntactical or API detail) is what you are after:

    StringBuffer b = new StringBuffer();
    boolean first = true;
    
    for (var t : collectionType) {
       if (first) {
          first = false;
       }
       else {
          b.add(", ");
       }
    
       b.add(t.toString());  
    }
    
    // Aggregated printable values are now b.toString()
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

My program has 100 threads. Every single thread does this: 1) if arrayList is
I want to merge sorted lists into a single list. How is this solution?
I want to add an element after every like button (chrome extension). Since posts
I want to add an element to every array in my multidimensional array. My
This ought to be ridiculously easy. I simply want to print a single element
I want add a key up event to every text box element in a
When you want to add whitespace between HTML elements (using CSS), to which element
I have a class and this class has one public element ArrayList myList.(I have
I want to add a border to every fifth element. The current code I
I want add label to every row in tableview at right side of the

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.