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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T15:57:01+00:00 2026-06-09T15:57:01+00:00

How should I declare main() method in Java? Like this: public static void main(String[]

  • 0

How should I declare main() method in Java?

Like this:

public static void main(String[] args)
{
    System.out.println("foo");
}

Or like this:

public static void main(String... args)
{
    System.out.println("bar");
}

What’s actually the difference between String[] and String... if any?

  • 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-09T15:57:03+00:00Added an answer on June 9, 2026 at 3:57 pm

    How should I declare main() method in Java?

    String[] and String... are the same thing internally, i. e., an array of Strings.
    The difference is that when you use a varargs parameter (String...) you can call the method like:

    public void myMethod( String... foo ) {
        // do something
        // foo is an array (String[]) internally
        System.out.println( foo[0] );
    }
    
    myMethod( "a", "b", "c" );
    
    // OR
    myMethod( new String[]{ "a", "b", "c" } );
    
    // OR without passing any args
    myMethod();
    

    And when you declare the parameter as a String array you MUST call this way:

    public void myMethod( String[] foo ) {
        // do something
        System.out.println( foo[0] );
    }
    
    // compilation error!!!
    myMethod( "a", "b", "c" );
    
    // compilation error too!!!
    myMethod();
    
    // now, just this works
    myMethod( new String[]{ "a", "b", "c" } );
    

    What’s actually the difference between String[] and String… if any?

    The convention is to use String[] as the main method parameter, but using String... works too, since when you use varargs you can call the method in the same way you call a method with an array as parameter and the parameter itself will be an array inside the method body.

    One important thing is that when you use a vararg, it needs to be the last parameter of the method and you can only have one vararg parameter.

    You can read more about varargs here: http://docs.oracle.com/javase/1.5.0/docs/guide/language/varargs.html

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

Sidebar

Related Questions

Classic example of a simple server: class ThreadPerTaskSocketServer { public static void main(String[] args)
I declared the following class class A { //not public public static void main(String
I guess the procedure should be something like this: declare @db varchar(100) declare @user
Should we declare the private fields as volatile if the instanced are used in
Should all structs and classes be declared in the header file? If I declare
I found a client/server code and I am getting this error: java.net.SocketException: Software caused
I need to declare finalizing method finalize() for all descendants of the base class
I have a Java problem with nested classes. My first class structure looked like
I wondered if it makes sense to declare a private method as final as
I've been trying to figure this out all night, but I guess my knowledge

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.