Java 对象的Arraylist是否为空?

Java 对象的Arraylist是否为空?,java,object,arraylist,Java,Object,Arraylist,所以在这个类中,对于选项==1,它不会通过对象的ArrayList进入for循环,这是否意味着对象是空的?因为我在开始时声明了对象并将它们添加到ArrayList存储中 public static void main(String[] args) { ArrayList<Team> store = new ArrayList<>(); Random gener = new Random(); String tourName

所以在这个类中,对于选项==1,它不会通过对象的ArrayList进入for循环,这是否意味着对象是空的?因为我在开始时声明了对象并将它们添加到ArrayList存储中

public static void main(String[] args) {
        ArrayList<Team> store = new ArrayList<>();
        Random gener = new Random();
        String tourName , tourDate , location;
        int maxNumberofTeams , avalSoft, avalHard , avalFieldTest;
        Scanner input = new Scanner(System.in);
        System.out.print("Please Enter tournament Name?\n");
        tourName = input.next();
        System.out.print("please Enter tournament Date\n");
        tourDate = input.next();
        System.out.print("please Enter location\n");
        location = input.next();
        System.out.print("Please Enter Max number of Teams\n");
        maxNumberofTeams = input.nextInt();
        System.out.print("Please Enter avalSoft\n");
        avalSoft = input.nextInt();
        System.out.print("Please enter aval Hard\n");
        avalHard = input.nextInt();
        System.out.print("Please Enter avalFieldTest\n");
        avalFieldTest = input.nextInt();
        Tournament tour = new Tournament (tourName , tourDate, location , maxNumberofTeams, avalSoft , avalHard, avalFieldTest);
        for (int i = 1 ; i <= maxNumberofTeams ; i++)
        {
            String teamName , sponsoringSchool , financialSponsor , judgeLocation;
            int teamNumber , noOfTeamMem , robotId;
            System.out.print("Please Enter %s team Name\n");
            teamName = input.next();
            System.out.print("Number of Team Memebers\n");
            noOfTeamMem = input.nextInt();
            System.out.print("Please Enter Sponsoring Schoolr\n");
            sponsoringSchool = input.next();
            System.out.print("Please Enter financialSponsor\n");
            financialSponsor = input.next();
            System.out.print("Please Enter judge Location\n");
            judgeLocation = input.next();
            teamNumber = i;
            System.out.print("Please Enter an ID for robot\n");
            robotId = input.nextInt();
            Robot robbb = new Robot();
            Team team = new Team(teamName , teamNumber , noOfTeamMem , sponsoringSchool , financialSponsor, judgeLocation, robbb);
            Robot rob = new Robot (team , robbb);
            store.add(team);
        }
        int choice=0;
        while(choice >= 0)
          {
            System.out.print("MENU\n"
                    + "1)PREPARING TEAM TURN ROBOT ON\n"
                    +"2)PREPARING TEAM HARDWARE\n"
                    + "3)HAVE HW INSPECT READY ROBOT\n"
                    + "4)HAVE PRERPARING TEAM TAKE HW_INSPECTED ROBOT TO STATION\n"
                    + "5)HAVE SW INSPECT ROBOT\n"
                    + "6)HAVE A PREPARING TEAM TAKE TO FIELD TEST\n"
                    + "7)HAVE A FIELD TEST INSPEC\n"
                    + "8)HAVE A BEFORE TEAM GO TO JUDGE\n"
                    + "9)HAVE JUDGES INTERVIEW\n"
                    + "10)CHANGE TEAM STATUS TO PASSED_INSPECTION\n"
                    + "11)TOURNAMENT STATUS TO MATCH\n"
                    + "12)\n"
                    + "13)ROBOT CAN'T PLAY IF OFF, READY, OR STILL AT TESTING\n"
                    + "14)CHANGE TOURNAMENT TO MATCHES\n"
                    + "15)GENERATE POINTS\n"
                    + "16)JUDGE POINTS\n"
                    + "17)CHANGE TOURNAMENT TO AWARDS\n"
                    + "18)PRINT TOP TEAMS JUDGING\n"
                    + "19) PRINT TOP BY QULIFYING \n"
                    + "20)DISPLAY TEAM PERSONS\n"
                    + "21)DISPLAY TEAM INFO\n"
                    + "22)DISPLAY INFO ABOUT ROBOTS\n"
                    + "23)INFO ABOUT TOURNAMENT\n"
                    + "24)END\n");

            choice = input.nextInt();
            Team temp = new Team();
            Robot robottemp = new Robot();
            Tournament tourr = new Tournament();
            if (choice == 1)
            {
                System.out.print("Phase"+choice);
                for (int i = 0 ; i >= store.size(); i++)
                {
                    System.out.print("Phase"+choice);
                    store.get(i).teamStatus = temp.teamStatus.PREPARING;
                    if (store.get(i).teamStatuss == 1)
                    {
                     store.get(i).robot.robotStatusChoice(1);
                     System.out.print("PHASE 1 COMPLETED\n");
                    }
                }
            }
publicstaticvoidmain(字符串[]args){
ArrayList store=新的ArrayList();
Random gener=新的Random();
字符串tourName、tourDate、位置;
int MaxNumberOfTeam、AVASOFT、avalHard、avalFieldTest;
扫描仪输入=新扫描仪(System.in);
系统输出打印(“请输入比赛名称?\n”);
tourName=input.next();
System.out.print(“请输入比赛日期\n”);
tourDate=input.next();
System.out.print(“请输入位置\n”);
location=input.next();
System.out.print(“请输入最大团队数量\n”);
maxNumberofTeams=input.nextInt();
System.out.print(“请输入AVASOFT\n”);
avalSoft=input.nextInt();
System.out.print(“请输入aval硬\n”);
avalHard=input.nextInt();
System.out.print(“请输入avalFieldTest\n”);
avalidfieldtest=input.nextInt();
巡回赛=新的巡回赛(巡回赛名称、巡回赛日期、地点、maxNumberofTeams、avalSoft、avalHard、avalFieldTest);
对于(int i=1;i=0)
{
系统输出打印(“菜单\n”
+“1)准备团队打开机器人\n”
+“2)准备团队硬件\n”
+“3)让硬件检查准备就绪\n”
+“4)让预备小组将HW_检查过的机器人带到车站\n”
+“5)让SW检查机器人\n”
+“6)让一个准备小组参加现场测试\n”
+“7)进行现场测试INSPEC\n”
+“8)在组队去裁判之前请有一个团队\n”
+“9)与法官面谈\n”
+“10)将团队状态更改为通过检查\n”
+“11)要匹配的锦标赛状态\n”
+“12)\n”
+“13)如果关闭、准备就绪或仍处于测试状态,ROBOT无法播放\n”
+“14)将比赛更改为比赛\n”
+“15)生成点\n”
+“16)评判分数\n”
+“17)将比赛更改为奖励\n”
+“18)打印顶级团队\n”
+“19)通过QULIFING打印顶部\n”
+“20)显示团队成员\n”
+“21)显示团队信息\n”
+“22)显示有关机器人的信息\n”
+“23)关于锦标赛的信息\n”
+“24)结束\n”);
choice=input.nextInt();
团队临时工=新团队();
Robot robottemp=新机器人();
锦标赛tourr=新锦标赛();
如果(选项==1)
{
系统输出打印(“阶段”+选择);
对于(int i=0;i>=store.size();i++)
{
系统输出打印(“阶段”+选择);
store.get(i).teamStatus=temp.teamStatus.PREPARING;
if(store.get(i).teamstatus==1)
{
store.get(i).robot.robotStatusChoice(1);
系统输出打印(“第1阶段已完成”);
}
}
}
这是我调用该方法的robot类

public int teamNumber;
    public int robotId;
    public Robot robot;
    Random gener = new Random();
    public int robotStatusChoice;
    ArrayList stations = new ArrayList();
    public int Height;
    public int Width = 22;
    public int Depth;
    public Team TeamAssigned = new Team("TEAMNAME", 1 , 1, "SS", "FS", "JL",robot);
    public robotStatus robotStatus;

    public Robot()
    {

    }
    public Robot( Team TeamAssigned ,Robot  robot){
        this.robot = robot;
        this.TeamAssigned = TeamAssigned;
    }


public void robotStatusChoice(int i) {
            if (i == 1)
            {
                this.robotStatusChoice = i;
                this.robotStatus = robotStatus.READY;
            }
            else if( i == 2)
            {
                this.robotStatusChoice = i;
                this.robotStatus = robotStatus.HW_INSP_PASSED;
            }
            else if ( i == 3)
            {
                this.robotStatusChoice = i;
                this.robotStatus = robotStatus.FIELD_TEST_PASSED;
            }
            else if ( i > 3 || i < 1)
            {
                this.robotStatusChoice = i;
                this.robotStatus = robotStatus.READY;
            }
        }
public int teamNumber;
公共智能机器人;
公共机器人;
Random gener=新的Random();
公共int机器人状态选择;
ArrayList stations=新的ArrayList();
公众内部高度;
公共整数宽度=22;
公众参与深度;
公共团队分配=新团队(“团队名称”,1,1,“SS”,“FS”,“JL”,机器人);
公共机器人地位机器人地位;
公共机器人()
{
}
公共机器人(团队分配,机器人机器人){
这个机器人=机器人;
this.TeamAssigned=TeamAssigned;
}
公共无效机器人状态选择(int i){
如果(i==1)
{
this.robotStatusChoice=i;
this.robotStatus=robotStatus.READY;
}
else如果(i==2)
{
this.robotStatusChoice=i;
this.robotStatus=robotStatus.HW_INSP_通过;
}
else如果(i==3)
{
this.robotStatusChoice=i;
this.robotStatus=robotStatus.FIELD\u测试通过;
}
否则如果(i>3 | | i<1)
{
this.robotStatusChoice=i;
this.robotStatus=robotStatus.READY;
}
}
团队状态变化

public void TeamStatus(int x)
    {
        if( x == 1 )
        {
            this.teamStatuss = x;
            this.teamStatus = teamStatus.PREPARING;
        }
        else if ( x == 2)
        {
            this.teamStatuss = x;
            this.teamStatus = teamStatus.PASSED_INSPECTION;
        }
        else if ( x == 3 )
        {
            this.teamStatuss = x;
            this.teamStatus = teamStatus.PLAYED5_MATCHES;
        }
        else if ( x == 4)
        {
            this.teamStatuss = x;
            this.teamStatus = teamStatus.INELIGIBLE;
        }
        else if ( x > 4 || x<1)
        {
            this.teamStatuss = x;
            this.teamStatus = teamStatus.INELIGIBLE;
        }


    }
public void TeamStatus(int x)
{
如果(x==1)
{
this.teamstatus=x;
this.teamStatus=teamStatus.PREPARING;
}
else如果(x==2)
{
this.teamstatus=x;
this.teamStatus=teamStatus.PASSED_检验;
}
else如果(x==3)
{
this.teamstatus=x;
this.teamStatus=teamStatus.PLAYED5_比赛;
}
否则(x==4)
{
this.teamstatus=x;
this.teamStatus=teamStatus.unquality;
}

否则,如果(x>4 | | x在你的
选择中==1
块的末尾,你的
for
循环条件是向后的。当条件是
true
而不是
false
时,将发生
for
循环的下一次迭代。反转你的条件

for (int i = 0 ; i < store.size(); i++)
for(int i=0;i
这就是问题所在:

for (int i = 0 ; i >= store.size(); i++)
除非
store
为空(在这种情况下会出现异常),
i>=store.size()
将立即为
false
。您的意思是:

for (int i = 0; i < store.size(); i++)
(你真的有
teamStatus
teamStatus
作为字段吗?那就是doe
for (Team team : store) {
    team.teamStatus = temp.teamStatus.PREPARING;
    if (team.teamStatuss == 1) {
        team.robot.robotStatusChoice(1);
        System.out.print("PHASE 1 COMPLETED\n");
    }
}
for (int i = 0 ; i >= store.size(); i++)
Robot robbb = new Robot();
Team team = new Team(teamName , teamNumber , noOfTeamMem , sponsoringSchool , financialSponsor, judgeLocation, robbb);
Robot rob = new Robot (team , robbb);
public void setRobot(Robot rob) { this.robot = rob; };