Java System.out.print不显示ArrayList

Java System.out.print不显示ArrayList,java,object,arraylist,system.out,Java,Object,Arraylist,System.out,对象accountData将不会显示在CloseAccount方法的控制台中。我尝试过for循环的各种变体,但它要么显示0。在页眉之后,或者在页眉之后什么都没有。我只希望能够将ArrayList的所有元素及其元素对象数据打印给用户 import java.util.*; public class AccountManagement { Scanner PETE = new Scanner(System.in); ArrayList<BankAccou

对象accountData将不会显示在CloseAccount方法的控制台中。我尝试过for循环的各种变体,但它要么显示0。在页眉之后,或者在页眉之后什么都没有。我只希望能够将ArrayList的所有元素及其元素对象数据打印给用户

import java.util.*;
    public class AccountManagement {
        Scanner PETE = new Scanner(System.in);
        ArrayList<BankAccount> accountData = new ArrayList<BankAccount>();
        public AccountManagement() {
            do {
                System.out.println("MANAGER (0) OR CUSTOMER (1): ");
                int userSelect = PETE.nextInt();
                if(userSelect == 0) {
                    Manager();
                    break;
                }else if(userSelect == 1){
                    Customer();
                    break;
                }else {
                    System.out.println("Please pick a valid selection");
                }
            }while(true);
            PETE.close();
        }
        private void Manager() {
            do {
                System.out.println("\t0. Open Account\n\t1. Close Account\n");
                int accountOpt = PETE.nextInt();
                if(accountOpt == 0) {
                    OpenAccount();
                }else if(accountOpt == 1) {
                    CloseAccount();
                }else {
                    System.out.println("Please pick a valid selection");
                }
            }while(true);
        }
        private void Customer() {
            do {
                //things
            }while(true);
        }
        private void OpenAccount() {
            do {
                System.out.println("Checking (0) or Savings (1): ");
                int CoS = PETE.nextInt();
                if(CoS == 0) {
                    System.out.println("SSN: ");
                    long SSN = PETE.nextLong();
                    System.out.println("PIN: ");
                    int PIN = PETE.nextInt();
                    Random rand = new Random();
                    int ACCNUM = rand.nextInt(10000);

                    CheckingAccount CA = new CheckingAccount(ACCNUM, PIN, SSN, 0);

                    System.out.println("Would you like to also add a savings account? (0 = Yes, 1 = No)");
                    int sav = PETE.nextInt();
                    if(sav == 0) {
                        ACCNUM = rand.nextInt(10000);
                        SavingsAccount SA = new SavingsAccount(ACCNUM, PIN, SSN, 0);
                        BankAccount BA = new BankAccount(CA, SA);
                        accountData.add(BA);
                    }else if (sav == 1) {
                        break;
                    }else {
                        System.out.println("Please enter a valid selection");
                    }
                }else if(CoS == 1) {
                    System.out.println("SSN: ");
                    long SSN = PETE.nextLong();
                    System.out.println("PIN: ");
                    int PIN = PETE.nextInt();
                    Random rand = new Random();
                    int ACCNUM = rand.nextInt(10000);

                    SavingsAccount SA = new SavingsAccount(ACCNUM, PIN, SSN, 0);

                    System.out.println("Would you like to also add a checking account? (0 = Yes, 1 = No)");
                    int check = PETE.nextInt();
                    if(check == 0) {
                        ACCNUM = rand.nextInt(10000);
                        CheckingAccount CA = new CheckingAccount(ACCNUM, PIN, SSN, 0);
                        BankAccount BA = new BankAccount(CA, SA);
                        accountData.add(BA);
                    }else if (check == 1) {
                        break;
                    }else {
                        System.out.println("Please enter a valid selection");
                    }
                }else {
                    System.out.println("Please pick a valid selection");
                }
            }while(true);
        }
        private void CloseAccount() {
            System.out.println("Which account would you like to close?");
            System.out.println("Selection\tCA ACCTNUM\tSA ACCTNUM");
            for(int x = 0; x < accountData.size(); x++) {
                System.out.println(x+".\t");
                System.out.print(accountData.get(x).CA.getAccountNumber()+"\t"+accountData.get(x).SA.getAccountNumber());
            }
            int selection = PETE.nextInt();
            accountData.remove(selection);
        }
        public ArrayList<BankAccount> getAccounts() {
            return accountData;
        }

    }

我刚刚在本地测试了一下,它可以打印出来。只需使用println而不是print来测试它

当我将print更改为println时,我得到如下打印数据:


皮特·克洛斯;对于您未创建的流(即关闭系统输入流)不是一个好主意您的输入数据是什么?你也可以分享你的测试数据吗?在我的代码中,有些情况下BankAccount对象不会被分配到ArrayList,所以野餐吧。谢谢你!