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

The Archive Base Latest Questions

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

Observe the following code: private List<List<Place>> m_grid = constructGrid(10000); private static List<List<Place>> constructGrid(int size)

  • 0

Observe the following code:

private List<List<Place>> m_grid = constructGrid(10000);

private static List<List<Place>> constructGrid(int size) {
  List<List<Place>> res = new ArrayList<List<Place>>(size);
  for (int i = 0; i < size; ++i) {
    res.add(null);
  }
  return res;
}

It is dull. Is there a prettier way to do the same thing? A one liner using some kind of a standard library?

Thanks.

EDIT

The list must be mutable. Hence, Collections.nCopies does not fit the bill.

  • 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-04T11:37:11+00:00Added an answer on June 4, 2026 at 11:37 am

    I don’t really get why you need 10000 nulls in your list, but if you want to do this, you can do:

    List<List<Place>> tmp = Collections.nCopies(10000, null); // immutable
    List<List<Place>> res = new ArrayList<List<Place>>(tmp);  // mutable
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

In my code I have the two following collections: private ObservableCollection<Job> listOfJobs1 = new
Why does this happen? Please observe the following code: static class StringExtension { public
I have the following code static void Main(string[] args) { //var source = BlockingMethod();
Let's observe the following segment of code in Java that uses System.currentTimeMillis() in a
Observe the following simple source code: using System; using System.Linq.Expressions; using System.Reflection; using System.Reflection.Emit;
Observe the following trivial anonymous type in C# new { X = 5 };
I have the following code to listen firefox quit-application event observe: function(subject, topic, data)
I have the following code snippet to enable extension after firefox quit, observe: function
I have the following code in a file called overlay.js: Event.observe(window, 'load', function() {
Observe the following code trait Example { type O def apply(o: O) def f(o:

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.