• 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
  • paul wheaton
  • Ron McLeod
  • Jeanne Boyarsky
Sheriffs:
  • Paul Clapham
Saloon Keepers:
  • Tim Holloway
  • Roland Mueller
Bartenders:

sun sites java Sample Question ??

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

5. Which correctly creates an array of five empty Strings (select all that apply)?
a>String a [ ] = new String [5]; for (int i = 0; i < 5; a[i++] = ""); <br /> b>String a [ ] = {"", "", "", "", ""};
c>String a [5];
d>String [ ] a = new String [5]; for (int i = 0; i < 5; a[i++] = null); <br /> e>String [5] a;


..
.
.
...
.
.
the correct answers are A and B.
Now I want to know why not D?
----------
 
Greenhorn
Posts: 17
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
There's no Strings created in d.
-VG.
 
Ranch Hand
Posts: 4716
9
Scala Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
the answer is that a null string is not the same thing as an empty string.
String s;
System.out.println(s)//prints "null"
String s = "";
System.out.println(s)//prints nothing
 
Greenhorn
Posts: 23
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Surprisingly, when I run the program it promped null in both the cases, Not blank and null, why? Are both the same? Then I have doubt about the original question. If it's null for A then A is also wrong answer. For your info. I have been using JDK 1.3.
 
sunil choudhary
Ranch Hand
Posts: 144
Redhat Java Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks Randell
I get your point.
in 1.2 it works fine
Albait:-> I had to assign the string to null.
________
Logic is the art of Non Contradictary existence
 
No. No. No. No. Changed my mind. Wanna come down. To see this tiny ad:
Clean our rivers and oceans from home
https://www.kickstarter.com/projects/paulwheaton/willow-feeders
reply
    Bookmark Topic Watch Topic
  • New Topic