Win a copy of Spring Boot in Practice this week in the Spring forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Tim Cooke
  • Ron McLeod
  • Jeanne Boyarsky
  • Paul Clapham
Sheriffs:
  • Liutauras Vilda
  • Henry Wong
  • Devaka Cooray
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • Al Hobbs
  • Carey Brown
Bartenders:
  • Piet Souris
  • Mikalai Zaikin
  • Himai Minh

Syntax of Array as parameter in JDK 1.6

 
Ranch Hand
Posts: 132
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Hi,

I am using jdk 6 compilation.
I have seen an example which has a method like follow



My Questions are:
1) Why jdk 6 uses notation '...' insted of '[]' notation at LINE 2 ? Is there any particular significance or reason?
2) What is advantage of this '...' sign.
3) If i make same notation at LINE 1 its giving me compilation error. Why? Does it used for passing parameter notation?


I don't have have any idea about that notation. Please tell me about it. I also run above program and it compiles fine.
I also saw this notation in one Question of SCJP 1.6 Version.
 
Bartender
Posts: 4179
22
IntelliJ IDE Python Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
The ... notation denotes 'varargs'. You are passing some number of Strings into the method,

See This Page for more info.
 
Ranch Hand
Posts: 624
IntelliJ IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
You can also check out this article on the subject. And if you go to this link, you can download chapter 5 of Java 1.5 Tiger: A Developer's Notebook. That chapter is on varagrs.
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
reply
    Bookmark Topic Watch Topic
  • New Topic