Monday 4 June 2012

startsWith Method of String


public class MyClass {
    public static void main(String[] args) {
        String [] words = {"tom","jerry","tomato","potato"};
       
        for(String w:words){
            if(w.startsWith("to")){
                System.out.println(w+" starts with to");
            }
        }
    }
}


Output:
tom starts with to
tomato starts with to


No comments:

Post a Comment

Note: only a member of this blog may post a comment.