title: How to splitting different special characters in Java with using if contains?
body: <p>I have “-“ characters in my strings as below.
  I am using if contains “-“ and splitting correctly. But some string values are also “-“ characters in different indexes.
  I tried to use 2nd if contains “.-“ cannot solve the issue as well.
  So have can I get correct outputs without “-“ characters perfectly?</p>
  <p>13-adana-demirspor -&gt; has 2 “-“ characters.</p>
  <p>15-y.-malatyaspor -&gt; has “-“ characters too.</p>
  <p>1st and 2nd strings makes problem for splitting.</p>
  <p>And others has only one “-“ character and no issue.</p>
  <p>My Code is:</p>
  <pre><code>final String [] URL  = {
              &quot;13-adana-demirspor&quot;,
              &quot;14-fenerbahce&quot;,
              &quot;15-y.-malatyaspor&quot;,
              &quot;16-trabzonspor&quot;,
              &quot;17-sivasspor&quot;,
              &quot;18-konyaspor&quot;,
              &quot;19-giresunspor&quot;,        
              &quot;20-galatasaray&quot;
            };
  
          for(int i=0; i&lt;URL.length; i++)
  
          String team;
  
      if (URL[i].contains(&quot;-&quot;)) {
          String[] divide = URL[i].split(&quot;-&quot;);
          team = divide[1];
          System.out.println(&quot;     &quot; + team.toUpperCase());
  
      } else if (URL[i].contains(&quot;.-&quot;)){
          String[] divide = URL[i].split(&quot;.-&quot;);
          team = divide[2];
          System.out.println(&quot;     &quot; + team.toUpperCase());
  
      }else {
          team = null;
      }
  </code></pre>
  <p>My Output is:</p>
  <p>ADANA ** missing second word</p>
  <p>FENERBAHCE</p>
  <p>Y. ** missing second word</p>
  <p>TRABZONSPOR</p>
  <p>SIVASSPOR</p>
  <p>KONYASPOR</p>
  <p>GIRESUNSPOR</p>
  <p>GALATASARAY</p>
  <p>Thanks for your help.</p>