开发者

Returning elements from array

I'm trying t开发者_如何学运维o return an array. Consider the following code.

public Quiz[] getMark(){
}

This is what i have as the return method. I want to return all the elements in the array under this method. I have to use return and the return type has to be Quiz[]

How would i start off?


May be this:

public Quiz[] getMark(){
  Quiz[] quizs;
  //--do some processing.
  //-- fill data in array
  return quizs;
}


are you looking for this

public Quiz[] getMark(){

Quiz [] quizArr = new Quiz[5]; quizArr[0]= new Quiz(); ... .. ..

return quizArr; }


i don't understand what is the problem , arrays in java are objects you just return it

a possible implementation

public Quiz[] getMark(){
    //init the quiz array
    Quiz[] array = new Quiz[5];
    // init each element in the quiz array
    for (int i=0;i<5;++i){
        array[i] = new Quiz();  // could use different constructor
    }
    return array;
}


Is this what you are looking for:

public Quiz[] getMark(){

return quizList.toArray(new Quiz[quizList.size()]()); 

}

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜