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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 2, 20262026-06-02T12:45:16+00:00 2026-06-02T12:45:16+00:00

We declare String array like- String[] a={A}; But when a method has String array

  • 0

We declare String array like-

String[] a={"A"};

But when a method has String array as argument, why can’t we call the method like-

mymethod({"A"});

Code-

class A{
    static void m1(String[] a) { }
    public static void main(String args[]){
        m1(new String []{});//OK
            m1({}); //Error
        }
    }
  • 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-02T12:45:18+00:00Added an answer on June 2, 2026 at 12:45 pm

    That’s just the way the language is specified. From section 10.6 of the JLS:

    An array initializer may be specified in a declaration (§8.3, §9.3, §14.4), or as part of an array creation expression (§15.10), to create an array and provide some initial values.

    So you’ve seen it working in a declaration, and an array creation expression is the form which includes new ArrayElementType at the start:

    myMethod(new String[] {"A"});
    

    Bear in mind that when it’s part of a declaration, there’s only one possible element type involved. For method invocations, it’s trickier – there could be multiple overloaded methods, etc. Basically, you’d need to make the expression {"A"} evaluate as a string array on its own, before participating in overload resolution.

    For a bit of comparison, the same is true in C#, although C# 3 introduced implicitly typed arrays where the element type is inferred from the values, so you’d be able to write:

    // C# 3
    MyMethod(new[] {"A"});
    

    You still need the new[] part though.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I would declare an empty String variable like this: string myString = string.Empty; Is
Ok, I have a hardcoded string I declare like this name = uPar Catégorie
In fortran, I can declare a character string as: character*80 mystring and then send
Possible Duplicate: Cannot declare Public static final String s = new String(“123”) inside an
How can I convert @lastEndTime to a string formated YYYY-MM-DD HH:MM:SS.MS ? DECLARE @lastEndTime
How can I cast a bigint variable to a string? DECLARE @id bigint
Ok so I have a string array like so: string[] myStringArray = new string[2];
I have declared the following method: private void mockInvokeDBHandler(Map<String, Object>... rows) { List<Map<String, Object>>
I have a working code (programmed by a tutorial) but like to dive in
I know you can't dynamically expand a normal array but is this a valid

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.