Logo 
Search:

Java Answers

Ask Question   UnAnswered
Home » Forum » Java       RSS Feeds
  Question Asked By: Loretta Carpenter   on Jan 10 In Java Category.

  
Question Answered By: Walborgd Fischer   on Jan 10

the efforts by u all ..help me to draw following conclusion..

String s="";
case1:

if (s==null || s.length()> 0 )
System.out.println("s==null || s.length()> 0 ");

here first conditon(s==null) is not met..second is also not met(||
s.length()> 0 )
as we cant assume String S="" and String =null; the same case...

Case2:
if (s==null || s.length()< 0 )
System.out.println("s==null || s.length()< 0 ");

here first condition is not met..as well as second also lead to false..

Case 3:

if (s==""|| s.length()< 0 )
System.out.println("s==""|| s.length()< 0 ");

here first condition is met..s=="" leads to true..so second condition is
nt chkd at all..

now if String=null;

if (s==""|| s.length()> 0 )
System.out.println("s==null || s.length()> 0 ");

now there will be NPE...for second condition..and first condition is not
met..

so wat i conclude is that
i) we can't calculate the length of a string which is set to null...and if its
not set to null..then the length is equal to the number of 16-bit Unicode
characters in the string..otherwise its zero(String s="";).
ii)we can't assume String s=null and String S="";..the same case..

Share: 

 

This Question has 1 more answer(s). View Complete Question Thread

 
Didn't find what you were looking for? Find more on java.lang.NullPointerException Or get search suggestion and latest updates.


Tagged: