Wednesday, May 18, 2011

Java: comparing chars

String messageText = "test";
char lastChar = messageText.charAt(messageText.length()-1);

if(lastChar!='e' && lastChar!='s' ){
      System.out.print("the last char is different of e and s , it's : "); // the last char is different of e and s , it's :
      System.out.println(lastChar); // t

}


Reference:
http://answers.yahoo.com/question/index?qid=20080914170215AAmVQQt

No comments: