• 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

arrays

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



C:\Program Files\Java\jdk1.5.0_12\bin>javac arr12.java
arr12.java:6: incompatible types
found : java.lang.String[]
required: java.lang.String
String s[]=new String[]{"anil",new String[]{"kumar","raj"}};//line 2
^
1 error



compile time error at Line2.please explain


As of my understanding an object array can take a String array or
a string and even object

whereas a string array can take only string or a string array
then what is wrong here??
 
Ranch Hand
Posts: 83
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
This would be valid:


See the difference? A String[] can only "hold" Strings, whereas a String[][] can hold references to arrays of Strings. An Object[] on the other hand could hold both.
 
reply
    Bookmark Topic Watch Topic
  • New Topic