package cs3500.tictactoe; import java.util.Arrays; import java.util.stream.Collectors; public class TicTacToeModel implements TicTacToe { // add your implementation here @Override public String toString() { // Using Java stream API to save code: return Arrays.stream(getBoard()).map( row -> " " + Arrays.stream(row).map( p -> p == null ? " " : p.toString()).collect(Collectors.joining(" | "))) .collect(Collectors.joining("\n-----------\n")); // This is the equivalent code as above, but using iteration, and still using the helpful // built-in String.join method. // List rows = new ArrayList<>(); // for(Player[] row : getBoard()) { // List rowStrings = new ArrayList<>(); // for(Player p : row) { // if(p == null) { // rowStrings.add(" "); // } else { // rowStrings.add(p.toString()); // } // } // rows.add(" " + String.join(" | ", rowStrings)); // } // return String.join("\n-----------\n", rows); } }