Advertisement
zachdyer

Java: String.startsWith & String.endsWith

May 26th, 2013
90
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.         String[] words2 = {"bob@gmail.com","sally@gmail.com","aurther@yahoo.com","pam@yahoo.com","arnold@msn.com","sal@gmail.com"};
  16.         //Loop through array
  17.         for(String word : words2){
  18.             //Print every email from the array that ends with gmail.com
  19.             if(word.endsWith("gmail.com")){
  20.                 System.out.println(word);
  21.             }
  22.         }
  23.     }
  24. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement