The file has a 1000 strings that look like this.
6S 8D KS 2D TH TD 9H JD TS 3S
KH JS 4H 5D 9D TC TD QC JD TS
QS QD AC AD 4C 6S 2D AS 3H KC
4C 7C 3C TD QS 9C KC AS 8D AD
KC 7H QC 6D 8H 6S 5S AH 7S 8C
3S AD 9H JC 6D JD AS KH 6S JH
AD 3D TS KS 7H JH 2D JS QD AC
9C JD 7C 6D TC 6H 6C JC 3D 3S
QC KC 3S JC KD 2C 8D AH QS TS
AS KD 3D JD 8H 7C 8C 5C QD 6C
Each represents a poker hand. The issue is each line has player one and player two. I am trying to split them up so I can figure out who won.
package pokerHandCalculator; import java.io.*; import java.util.ArrayList; public class PokerCalculator { ArrayList<String>pokerHands = new ArrayList<String>(); void readFile() { String line; try { FileReader file = new FileReader("poker.txt"); BufferedReader buffer = new BufferedReader(file); while((line=buffer.readLine()) != null) { pokerHands.add(line); } buffer.close(); } catch(Exception ex) { System.out.println("The file was not read or not found "+ ex); } } void print() { int count=0; for(String s: pokerHands) { System.out.println(s); count++; } System.out.println(count); } public static void main(String[] args) { PokerCalculator poker = new PokerCalculator(); poker.readFile(); poker.print(); } }
I have tried to handle it like this along with a few other unsuccessful ways:
void separateHand() { //ArrayList<String> hands = (ArrayList<String>) pokerHands.subList(0,5); ArrayList<String>hands = new ArrayList<String>(); int count=0; /*pokerHands has all the variables from the file in lines of ten strings reading like: QC KC 3S JC KD 2C 8D AH QS TS AS KD 3D JD 8H 7C 8C 5C QD 6C Below should break them up into separate arrays of 5 cards * */ for(String s : pokerHands) { count++; if(count % 5 == 0) { hands = new ArrayList<String>(); hands.add(s); } else { hands.add(s); } } for(String list: hands)//Testing if it worked { System.out.println(list); } }
Also posted at http://www.java-forums.org/new-java/...oker-game.html