title: How to check if a Strings ends with any entry in a list of Strings in Java
body: <p>I have a file name and a list of extensions. I want to check if the file name ends with any of the extensions in the list I have.</p>
  
  <pre><code>String fileName = "abc.txt";
  String[] extensions = {".txt", ".doc", ".pdf"};
  </code></pre>
  
  <p>I can manually go over the list of extensions and check if the file ends with any of the extensions in my list. </p>
  
  <pre><code>public static boolean checkIfFileHasExtension(String s, String[] extn) {
      for (String entry : extn) {
          if (s.endsWith(entry)) {
              return true;
          }
      }
      return false;
  }
  
  public static void main (String[] args) throws java.lang.Exception
  {
      // your code goes here
  
      String fileName = "abc.txt";
      String[] extensions = {".txt", ".doc", ".pdf"};
      System.out.println(checkIfFileHasExtension(fileName, extensions));
  }
  </code></pre>
  
  <p>Is there a better way of doing it using StringUtils or Streams or any other Java libraries? I am looking for a one-liner. Thanks!</p>