提出一个思路,使用Iterator返回多值,但是不推荐使用.example as below.

import java.util.Iterator;

public class Test

{

public static Iterator getMultiValues(){

return new Iterator() {

int[] values = {0,1};

int cursor = 0;

public boolean hasNext() {

return cursor

}

public Integer next() {

return values[cursor++];

}

public void remove() {

// TODO Auto-generated method stub

}

};

}

public static void main(String[] args){

Iterator itor = getMultiValues();

while(itor.hasNext()){

System.out.println(itor.next());

}

/**

* console:

* 1

* 2

*

* besides , you can return any amount of value,but it is not recommended

*/

}

}

Logo

汇聚全球AI编程工具,助力开发者即刻编程。

更多推荐