简体   繁体   中英

How do i return a class member that is an array in Java?

trying to get the return function to return the full array, but not able to do it with a for loop or without. is there any way to get this done?

    
    String Game;
    String Coach;
    String Player[];
    
    public void setPlayer(String a[])
    {
       
        for (int i = 2; i<10; i++)
        {
            Player[i-2] = a[i];
        }
    }
    
    public String getPlayer()
    {
        for(int i = 0; i < 8; i++)
        {
            return Player[i];
        }
        
    }

There's nothing special about arrays - you can return the member as is:

public String[] getPlayer() {
    return Player;
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM