简体   繁体   English

如何返回 Java 中的数组的 class 成员?

[英]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.试图获得返回 function 以返回完整数组,但无论是否使用 for 循环都无法做到。 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: arrays 没有什么特别之处 - 您可以按原样返回成员:

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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