title: Avoiding multiple If statements in Java
body: <p>I've coded a method something like this. But I guess this should undergo refactoring.
  Can any one suggest the best approach to avoid using this multiple if statements?</p>
  
  <pre><code>private String getMimeType(String fileName){
    if(fileName == null) {
      return "";   
    } 
    if(fileName.endsWith(".pdf")) {
      return "application/pdf";   
    }
    if(fileName.endsWith(".doc")) {
      return "application/msword";  
    }
    if(fileName.endsWith(".xls")) {
      return "application/vnd.ms-excel"; 
    }
    if(fileName.endsWith(".xlw")) {
      return "application/vnd.ms-excel"; 
    }
    if(fileName.endsWith(".ppt")) {
      return "application/vnd.ms-powerpoint"; 
    }
    if(fileName.endsWith(".mdb")) {
      return "application/x-msaccess"; 
    }
    if(fileName.endsWith(".rtf")) {
      return "application/rtf"; 
    }
    if(fileName.endsWith(".txt")) {
      return "txt/plain"; 
    }
    if(fileName.endsWith(".htm") || fileName.endsWith(".html")) {
      return "txt/html"; 
    }
    return "txt/plain"; 
  }
  </code></pre>
  
  <p>I cannot use switch-case here as my 'condition' is a <code>java.lang.String</code>.</p>