mardi 15 août 2017

How to make an if-else if statement search and delete something in a List

My question is simple, I would like to make it so that a

if () {

} else {

}

statement can search for something and keep it, deleting the rest. My code, and the parts I want to change are here:

import java.util.Arrays;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;

public class cardGame {
  public static void main(String[] args) {
    List<String> deck = Arrays.asList("Ace of spades", "2 of spades", "3 of spades", "4 of spades", "5 of spades", "6 of spades", "7 of spades", "8 of spades", "9 of spades", "10 of spades", "Jack of spades", "Queen of spades", "King of spades", "Ace of spades", "2 of spades", "3 of spades", "4 of spades", "5 of spades", "6 of spades", "7 of spades", "8 of spades", "9 of spades", "10 of spades", "Jack of spades", "Queen of spades", "King of spades", "Ace of hearts", "2 of hearts", "3 of hearts", "4 of hearts", "5 of hearts", "6 of hearts", "7 of hearts", "8 of hearts", "9 of hearts", "10 of hearts", "Jack of hearts", "Queen of hearts", "King of hearts", "Ace of diamonds", "2 of diamonds", "3 of diamonds", "4 of diamonds", "5 of diamonds", "6 of diamonds", "7 of diamonds", "8 of diamonds", "9 of diamonds", "10 of diamonds", "Jack of diamonds", "Queen of diamonds", "King of diamonds", "Ace of clubs", "2 of clubs", "3 of clubs", "4 of clubs", "5 of clubs", "6 of clubs", "7 of clubs", "8 of clubs", "9 of clubs", "10 of clubs", "Jack of clubs", "Queen of clubs", "King of clubs");
    List<String> trump = Arrays.asList("spades", "hearts", "diamonds", "clubs");

    Collections.shuffle(deck);
    Collections.shuffle(trump);

    List<String> p1hand = deck.subList(0, 5);
    List<String> p2hand = deck.subList(5, 10);
    List<String> p3hand = deck.subList(10, 15);
    List<String> p4hand = deck.subList(15, 20);

    System.out.println("Boure hands and trump game.");
    System.out.println("");
    System.out.println("Trump: " + trump.subList(0, 1));
    System.out.println("");
    System.out.println("P1hand: " + p1hand);
    System.out.println("");
    System.out.println("P2hand: " + p2hand);
    System.out.println("");
    System.out.println("P3hand: " + p3hand);
    System.out.println("");
    System.out.println("P4hand: " + p4hand);
    }
}

Aucun commentaire:

Enregistrer un commentaire