Tuesday, June 23, 2009

How to Compare Strings


String s1 = "a";
String s2 = "A";

// Check if identical
boolean b = s1.equals(s2); // false

// Check if identical ignoring case
b = s1.equalsIgnoreCase(s2); // true

StringBuffer sbuf = new StringBuffer("a");
b = s1.contentEquals(sbuf); // true

0 comments:

 

Sample Java Codes Copyright © 2008 Green Scrapbook Diary Designed by SimplyWP | Made free by Scrapbooking Software | Bloggerized by Ipiet Notez