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

  • Home
  • SEARCH
  • 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 8446193
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T09:51:51+00:00 2026-06-10T09:51:51+00:00

After search around google I couldn’t find a answer for that, I’m not too

  • 0

After search around google I couldn’t find a answer for that, I’m not too familiar to Java, I use C# most of the time and I know that using C# it is possible to do and probably it is in Java.

Ps: Sorry the Highlight, I don’t know how to use that here.

I have a constructor:

public WeaponsData(ArrayList<NPC> _drop, ArrayList<NPC> _buy, ArrayList<NPC> _sell) { }

Then when I try to create the Object creating the ArrayLists() directly on it, it doesn’t work:

public static WeaponsData AngelicAxe = new WeaponsData(new ArrayList<NPC>() { new NPC("Rat", "None", 0), new NPC("Dog", "None", 0) },
                new ArrayList<NPC>() { new NPC("Player", "All", 0) },
                new ArrayList<NPC>() { new NPC("Cain", "First", 5000) }
                );

There is no way to do that on Java?

Thank you

  • 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-10T09:51:52+00:00Added an answer on June 10, 2026 at 9:51 am

    ArrayList does not have the constructors necessary to do that. You can either wrap the arguments in a call to Arrays.asList():

    public static WeaponsData AngelicAxe = new WeaponsData(
        new ArrayList<NPC>(
           Arrays.asList(
              new NPC("Rat", "None", 0),
              new NPC("Dog", "None", 0)
           )
        ),
    // etc
    );
    

    or use the factory methods provided by the Guava Framework:

    public static WeaponsData AngelicAxe = new WeaponsData(
        Lists.newArrayList(
            new NPC("Rat", "None", 0),
            new NPC("Dog", "None", 0)
        ),
    // etc.
    );
    

    Of course, if you use Guava, you should probably use an immutable collection instead, as you are apparently trying to implement a constant:

    public static final WeaponsData ANGELIC_AXE = new WeaponsData(
        ImmutableList.of(
            new NPC("Rat", "None", 0),
            new NPC("Dog", "None", 0)
        ),
    // etc.
    );
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

After having a search around I could not find exactly what I want, I
here's a Fusion Tables map that's broken after a search. It does everything well
After a painful search for Python XMPP library to use for XEP 060 I
After an extensive search I have been unable to find any information on this
After doing a long search on stackoverflow i didn't find any one talked about
I wonder if anyone can help? After Google announced that it will take note
I looked around some and didn't find what I was after so here goes.
iv'e been searching around but it's hard to find an answer for this specific
I started looking around for a search engine and after some reading I decided
I've got a bit of a tricky question I couldn't find the answer to.

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.