Check if a string ends With Prefixes - Java java.lang

Java examples for java.lang:String End

Description

Check if a string ends With Prefixes

Demo Code


//package com.java2s;

public class Main {
    public static void main(String[] argv) {
        String str = "java2s.com";
        String[] prefixes = new String[] { "1", "abc", "level", null,
                "java2s.com", "asdf 123" };
        System.out.println(endsWithPrefixes(str, prefixes));
    }/*from   w  ww. ja va2s  . c o  m*/

    public static boolean endsWithPrefixes(String str, String[] prefixes) {
        for (String prefix : prefixes)
            if (str.endsWith(prefix))
                return true;
        return false;
    }
}

Related Tutorials