• 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
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

String array initialization with constant values

 
Ranch Hand
Posts: 157
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
What is exactly the difference between:

String[][] valuesa = {{""}};
and:
String[][] valuesb = new java.lang.String[][]{new java.lang.String[]{""}};

or is it just the same may-be?


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



The above code produces 1,1,1,1.

Both are double dimenson arrays, elements of double dimension arrays are nothing but ..one dimenson array.

String[][] valuesb = new String[][]{new String[]{""}}; is anonymous 2 dimensional array creation

For exam ..I think just remembering the syntax of anonoymous 1d will be good enough..

its like

String[] valuec = new String[]{new String("")};
 
Ranch Hand
Posts: 194
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
String[] varName = {};

That implicitly creates an array. I just read that in the JLS 3.0.
 
Sheriff
Posts: 9708
43
Android Google Web Toolkit Hibernate IntelliJ IDE Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Ryan Beckett wrote:String[] varName = {};

That implicitly creates an array. I just read that in the JLS 3.0.



But Ryan that would create a zero length array and the code in this question will create a one length array...
 
Consider Paul's rocket mass heater.
reply
    Bookmark Topic Watch Topic
  • New Topic