zachdyer

Java: String.startsWith & String.endsWith

May 26th, 2013
115
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.65 KB | None | 0 0
  1.  
  2. class Java{
  3.     public static void main(String args[]){
  4.         //An array of words
  5.         String[] words = {"Sword","Armor","Boots","Helmet","Saddle"};
  6.        
  7.         //Loop through array
  8.         for(String word : words){
  9.             //Print every word in the array that starts with "S"
  10.             if(word.startsWith("S")){
  11.                 System.out.println(word);
  12.             }
  13.         }
  14.        
  15.         //Loop through array
  16.         for(String word : words2){
  17.             //Print every email from the array that ends with gmail.com
  18.             if(word.endsWith("gmail.com")){
  19.                 System.out.println(word);
  20.             }
  21.         }
  22.     }
  23. }
Advertisement
Add Comment
Please, Sign In to add comment