title: Detect straight hand in poker
body: <p>Ok, so, I have the method <code>straight(ArrayList&lt;Card&gt; l)</code> defined below. It works but I really want to improve it because my algorithm is running quite slow.</p>
  
  <p>The idea here is: get all value of the Cards and add them to an arraylist, then check whether the arraylist contain the list of straights or not. If yes, add it to a hashmap, the last array added will be the best straight (in case there are 3 straight: 1 2 3 4 5 6 7)</p>
  
  <p>The Card is define by 2 arrays: value and suit which are:</p>
  
  <pre><code>private String[] name = {"Joker", "Ace", "2", "3", "4", "5", "6", "7", "8", "9", "10", "Jack", "Queen", "King"};
  private String[] suit = {"Club", "Diamond", "Spade", "Heart"};
  </code></pre>
  
  <p>So I have 2 questions:</p>
  
  <p>1, Is there anyway to improve the code below?</p>
  
  <p>2, I do this project for fun, I want this to be multiple player. So should the server detect the best hand of each player or players do that and then send the result back to server by a pair in form of (String, ArrayList bestHand)?</p>
  
  <pre><code>public ArrayList&lt;Card&gt; straight(ArrayList&lt;Card&gt; l){
          ArrayList&lt;Card&gt; straight = new ArrayList&lt;&gt;();
          ArrayList&lt;Card&gt; card_value = this.removeDuplicate(l);
          ArrayList&lt;Integer&gt; temp_value = this.getCardValue(card_value);
  
          ArrayList&lt;Integer[]&gt; possible_straight = new ArrayList&lt;&gt;();
          possible_straight.add(new Integer[]{1, 2, 3, 4, 5});
          possible_straight.add(new Integer[]{2, 3, 4, 5, 6}); 
          possible_straight.add(new Integer[]{3, 4, 5, 6, 7});
          possible_straight.add(new Integer[]{4, 5, 6, 7, 8});
          possible_straight.add(new Integer[]{5, 6, 7, 8, 9});
          possible_straight.add(new Integer[]{6, 7, 8, 9, 10});
          possible_straight.add(new Integer[]{7, 8, 9, 10, 11});
          possible_straight.add(new Integer[]{8, 9, 10, 11, 12});
          possible_straight.add(new Integer[]{9, 10, 11, 12, 13});
          possible_straight.add(new Integer[]{10, 11, 12, 13, 1});
  
          HashMap&lt;Integer, Integer[]&gt; check_list = new HashMap&lt;&gt;();
          int controller = 0;
  
          for (int i = 0; i &lt; possible_straight.size(); i++){
              Integer[] dummy = possible_straight.get(i);
              if (temp_value.containsAll(Arrays.asList(dummy))){
                  check_list.put(controller++, dummy);
              }
          }
  
          if (!check_list.isEmpty()){
              for (int k = 0; k &lt; check_list.get((controller - 1)).length; k++){
                  for (int m = 0; m &lt; card_value.size(); m++){
                      Card temp_card = card_value.get(m);
                      if (temp_card.getValue() == check_list.get(controller - 1)[k]){
                        straight.add(temp_card);
                      }
                  }
              }
          }
  
          return straight;
      }
  </code></pre>