Results 1 to 5 of 5
  1. #1
    Join Date
    Jan 2009
    Posts
    14
    Rep Power
    0

    Default String[] arg and String... args

    Hi All,

    As in Java 1.5 and lateral we can use String... arg instead of String [] args in

    public static void main() method.

    so it means if we can use both of them as a interchangebly.

    is this true? if yes the what would be the answer of below question?

    logIt(”log message 1 “);
    logIt(”log message2”,”log message3”);
    logIt(”log message4”, “log message5”, “log message6);
    Which declaration satisfies this requirement?

    A. public void logIt(String * msgs)
    B. public void logIt(String [] msgs)
    C. public void logIt(String... msgs)
    D. public void logIt(String msg1, String msg2, String msg3)

    Answer: ??

    Regards,
    Mahendra Athneria
    Mumbai
    India

  2. #2
    Supamagier is offline Senior Member
    Join Date
    Aug 2008
    Posts
    384
    Rep Power
    7

    Default

    C, obviously. You should know why - if you get this question. If you don't, post. :)
    I die a little on the inside...
    Every time I get shot.

  3. #3
    CJSLMAN's Avatar
    CJSLMAN is offline Moderator
    Join Date
    Oct 2008
    Location
    Mexico
    Posts
    1,159
    Rep Power
    8

    Default varargs ... a creature out of a Tolkein book?

    Doing some searching, I found the following information...

    Passing Information to a Method or a Constructor (see "Arbitrary Number of Arguments" section)
    Java Varargs
    Java Tips - Using the VarArgs Language Feature

    So the name of this beast (Object... arguments) is called "varargs".

    Luck,
    CJSL
    Chris S.
    Difficult? This is Mission Impossible, not Mission Difficult. Difficult should be easy.

  4. #4
    Join Date
    Jan 2009
    Posts
    14
    Rep Power
    0

    Default

    Thanks Chris for your Answer. :)

    Regards,
    Mahendra

  5. #5
    CJSLMAN's Avatar
    CJSLMAN is offline Moderator
    Join Date
    Oct 2008
    Location
    Mexico
    Posts
    1,159
    Rep Power
    8

    Default

    Welcome...
    Chris S.
    Difficult? This is Mission Impossible, not Mission Difficult. Difficult should be easy.

Similar Threads

  1. Why can't we write main without String args[]
    By shailender in forum New To Java
    Replies: 6
    Last Post: 06-17-2013, 10:28 AM
  2. combine string[] into string like perl's join function
    By tekberg in forum Advanced Java
    Replies: 9
    Last Post: 02-23-2009, 02:05 PM
  3. Replies: 9
    Last Post: 11-23-2008, 12:03 AM
  4. [SOLVED] ReadLine(String fmt,Object... args) of Console class
    By Pooja Deshpande in forum New To Java
    Replies: 4
    Last Post: 04-25-2008, 06:51 AM
  5. Replies: 0
    Last Post: 11-20-2007, 05:59 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •