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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T03:29:01+00:00 2026-05-25T03:29:01+00:00

This is a simple question but if I do List<Object> list = getObjectsFromDatabase(); This

  • 0

This is a simple question but if I do

List<Object> list = getObjectsFromDatabase();

This would not be the correct way to handle this?

But this would?

List<Object> firstList = getObjectsFromDatabase();

List<Object> list = new ArrayList<Object>(firstList);

Or if I had a class

public class ReportDisplayModel<T> {

    public ReportDisplayModel(List<T> data) {
        this.data = data;
    }
    public List<T> data;
}

And I wanted to set the data in this model I would use the constructor?

ReportDisplayModel<Object> model = new ReportDisplayModel<Object>(getData());

Instead of

ReportDisplayModel<Object> model = new ReportDisplayModel<Object>();

model.data = getData();

Just need a clarification. Thanks.

  • 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-05-25T03:29:02+00:00Added an answer on May 25, 2026 at 3:29 am

    Regarding

    List<Object> list = getObjectsFromDatabase();
    

               vs

    List<Object> firstList = getObjectsFromDatabase();
    List<Object> list = new ArrayList<Object>(firstList);
    

    either approach is fine. Depends on if you want list to refer to the list returned by getObjectsFromDatabase() or if you want it to refer to a copy of it.

    If simply want to, say, print the database objects, the first approach is fine.

    If you want to, say, filter out half of the database objects (i.e., remove objects from the list), and you can’t say for sure that getObjectsFromDatabase() returns a mutable list, then you’ll have to go with the second approach.


    Regarding

    ReportDisplayModel<Object> model = new ReportDisplayModel<Object>(getData());
    

               vs

    ReportDisplayModel<Object> model = new ReportDisplayModel<Object>();
    model.data = getData();
    

    I’d prefer the first method. Simply because I wouldn’t want to worry about null pointer exceptions etc if I accidentally do something like

    ReportDisplayModel<Object> model = new ReportDisplayModel<Object>();
    model.printData();
    model.data = getData();
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

may be too simple groovy question but....please help i have a list like this:
This is probably a simple question but I am not an ASP.NET developer and
This is probably a really simple question but... I would like to do a
i think this is a simple question but I've searched around and can't seem
This is probably a simple question but I can't seem to find the solution.
This may seem like a simple question but i am getting an error when
This is probably a simple question but I can't seem to figure out how
This is a pretty simple question but I'm somewhat stumped. I am capturing sections
This might be a simple question but I'm just picking this up so please
This is probably a simple question but I am developing a web app in

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.