List of usage examples for org.apache.commons.lang3 StringUtils countMatches
public static int countMatches(final CharSequence str, final char ch)
Counts how many times the char appears in the given string.
A null or empty ("") String input returns 0 .
StringUtils.countMatches(null, *) = 0 StringUtils.countMatches("", *) = 0 StringUtils.countMatches("abba", 0) = 0 StringUtils.countMatches("abba", 'a') = 2 StringUtils.countMatches("abba", 'b') = 2 StringUtils.countMatches("abba", 'x') = 0
From source file:yatze.FXMLDocumentController.java
@FXML private void yatzy(ActionEvent event) { yatzyButton.setDisable(true);/* w w w . java 2 s . co m*/ String diceString = ""; for (int i : dice) { diceString = diceString + Integer.toString(i); } int ones2 = StringUtils.countMatches(diceString, "1"); int twos2 = StringUtils.countMatches(diceString, "2"); int threes2 = StringUtils.countMatches(diceString, "3"); int fours2 = StringUtils.countMatches(diceString, "4"); int fives2 = StringUtils.countMatches(diceString, "5"); int sixes2 = StringUtils.countMatches(diceString, "6"); if (ones2 == 5 || twos2 == 5 || threes2 == 5 || fours2 == 5 || fives2 == 5 || sixes2 == 5) { kogusumma = kogusumma + 50; Yatzy.setText(Integer.toString(50)); } kogusumma = kogusumma + hetkeSumma; resetRolls(); }