1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 |
/* String endsWith Example This example shows how to check if a particular string is ending with a specified word. */ public class StringEndsWithExample { public static void main(String[] args) { //declare the original String String strOrig = "Hello World"; /* check whether String ends with World or not. Use endsWith method of the String class to check the same. endsWith() method returns true if a string is ending with a given word otherwise it returns false */ if(strOrig.endsWith("World")){ System.out.println("String ends with World"); }else{ System.out.println("String does not end with World"); } } } /* Output of the program would be : String ends with World */ |
wow…thanks a lot for these examples…
if (!mystring.getName().toLowerCase().endsWith(“.txt”))
System.out.println(lista[i].getName() + ” not shown, is not a known file”);
else {
// work with the file
}