Monday 16 June 2014

endsWith (String suffix)

public boolean endsWith(String suffix)
true if the character sequence represented by the argument is a suffix of the character sequence represented by this object; false otherwise.

class StringEndsWith{
 public static void main(String args[]){
  String str = new String("Hello");
  
  System.out.print("Is str ends with \"o\" ");
  System.out.println(str.endsWith("o"));
  System.out.print("Is str ends with \"lo\" ");
  System.out.println(str.endsWith("o"));
  System.out.print("Is str ends with \"llo\" ");
  System.out.println(str.endsWith("o"));
  System.out.print("Is str ends with \"a\" ");
  System.out.println(str.endsWith("a"));
 }
}

Output
Is str ends with "o" true
Is str ends with "lo" true
Is str ends with "llo" true
Is str ends with "a" false

 1. The result will be true if the argument is the empty string.
class StringEndsWith1{
 public static void main(String args[]){
  String str = new String("Hello");
  
  System.out.print("Is str ends with empty ");
  System.out.println(str.endsWith(""));
 }
}

Output
Is str ends with empty true


Prevoius                                                 Next                                                 Home

No comments:

Post a Comment