Wednesday, February 6, 2013

KNOWLEDGE HUB: Java Openigns -Infoys

KNOWLEDGE HUB: Java Openigns -Infoys: Hi All, In Infosys  Openings are there on Java 3+ . Please send u r profiles to sambamca06@gmail.com Note:Plz send only genuine profi...

StringUtils.isNotEmpty() VS StringUtils.isNotBlank() in Java

isNotEmpty

public static boolean isNotEmpty(String str)
Checks if a String is not empty ("") and not null.
 StringUtils.isNotEmpty(null)      = false
 StringUtils.isNotEmpty("")        = false
 StringUtils.isNotEmpty(" ")       = true
 StringUtils.isNotEmpty("bob")     = true
 StringUtils.isNotEmpty("  bob  ") = true
 



Parameters:
str - the String to check, may be null

Returns:
true if the String is not empty and not null



isNotBlank

public static boolean isNotBlank(String str)
Checks if a String is not empty (""), not null and not whitespace only.
 StringUtils.isNotBlank(null)      = false
 StringUtils.isNotBlank("")        = false
 StringUtils.isNotBlank(" ")       = false
 StringUtils.isNotBlank("bob")     = true
 StringUtils.isNotBlank("  bob  ") = true
 



Parameters:
str - the String to check, may be null

Returns:
true if the String is not empty and not null and not whitespace








Java Openigns -Infoys

Hi All,

In Infosys  Openings are there on Java 3+ .

Please send u r profiles to sambamca06@gmail.com

Note:Plz send only genuine profiles.

Pawar Star Pavan Kalyan








StringUtils.isEmtpty() vs StringUtils.isBlank() in Java



1) isEmpty

public static boolean isEmpty(String str)
Checks if a String is empty ("") or null.

StringUtils.isEmpty(null) = true
StringUtils.isEmpty("") = true
StringUtils.isEmpty(" ") = false
StringUtils.isEmpty("bob") = false
StringUtils.isEmpty(" bob ") = false


2) isBlank

public static boolean isBlank(String str)
Checks if a String is whitespace, empty ("") or null.

StringUtils.isBlank(null) = true
StringUtils.isBlank("") = true
StringUtils.isBlank(" ") = true
StringUtils.isBlank("bob") = false
StringUtils.isBlank(" bob ") = false

Difference between NULL and empty string in Java

What is difference between null string (String abc = null) and empty string (String abc = "") ?

Analysis:
--------
Try to call a method on both of them and you'll see the difference


  1. String s = "";   s.length();  
you actually declare a new String Object, and it means the variable (in this case - s) has a String Object associated to it. you can call String methods on that object.
it is like typing:
              String s = new String();
  if you type:   String s = "";   s.lentgh; // return 0  

   2.   String s = null;   s.length();
    s.lentgh;//returns a null pointer exception

 Basically a reference to an empty string points to an object in the heap so you can call methods on it. But a reference pointing to null has no object to point in the heap and thus you'll get a Null Pointer Exception