Complete the method sortSuits(). This method takes oneargument:a deck of cards (Stack deck).It shouldreturn an ArrayList of Stacks, each stack representing all thecards of one suit(i.e., if you have four suits-Spades,Hearts,Clubs,Diamonds, it should return ArrayLists ofSpades,Hearts,Clubs,and Diamonds). The returned ArrayList should bein the same order as the SUITSarray. Use a loop to look at eachcard, determine its suit (methods such as peek()/pop()andString.contains()may be helpful), and move the card from the deckto the stack associated with its suit.
package L2;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.Stack;
public class CardSort {
 Â
  public static final String[] RANKS ={\"Ace\",\"2\",\"3\",\"4\",\"5\",\"6\",\"7\",\"8\",\"9\",\"10\",\"Jack\",\"Queen\",\"King\"};
  public static final String[] SUITS ={\"Spades\",\"Hearts\",\"Clubs\",\"Diamonds\"};
 Â
  public static void main(String[] args) {
     /* DO NOT EDIT THE MAIN METHOD*/
    Â
     //make a deck of cards, should have52 cards
     Stack deck =makeDeck();
     System.out.println(\"New deck:\"+deck.size()+\" cards\");
     System.out.println(deck);
     System.out.println();
    Â
     //automatically shuffles the deck,don't need to code this
     Collections.shuffle(deck);
     System.out.println(\"Shuffled deck:\"+deck.size()+\" cards\");
     System.out.println(deck);
     System.out.println();
    Â
     //create an ArrayList of Stacks,each representing all the cards of one suit
     ArrayList> bySuit =sortSuits(deck);
     for(int i = 0; i         //each new stackshould have 13 cards, all the same suit
        System.out.println(SUITS[i]+\": \"+bySuit.get(i).size()+\"cards\");
        System.out.println(bySuit.get(i));
        System.out.println();
     }
    Â
     //the deck should now beempty
     System.out.println(\"Deck is empty?\"+deck.isEmpty()+\" (\"+deck.size()+\" cards)\");    Â
  }
 Â
  public static Stack makeDeck() {
    Â
     /* YOUR CODE HERE */
     int n = SUITS.length *RANKS.length;
     String[] deck = newString[n];
     for (int i = 0; i         for (int j = 0;j < SUITS.length; j++) {
           deck[SUITS.length*i + j] = RANKS[i] + \" of \" +SUITS[j];
        }
     } Stack stack2 =new Stack();
     for(String text:deck) {stack2.push(text);
     }
     return (Stack) stack2;
 Â
  }
 Â
  public static ArrayList>sortSuits(Stack deck) {
     return null;
 Â
  }
}