When we need more than one return parameters##
Method 1
使用容器:
Vector, HashSet, HashMaq and so on
Method 2
将返回值当做参数传入
例如:
import java.util.HashSet; public class Return { public static void main(String[] args) {
HashSet<Integer> set = new HashSet<Integer>();
Alphabet alphabet = null;
Integer a = new Integer(1);
Double b = new Double(2.0);
int c = 3;
System.out.println("Before~~~");
System.out.println("Set:"+set.size());
System.out.println("a: "+a);
System.out.println("b: "+b);
System.out.println("c: "+c);
myReturn(set, alphabet, a, b, c);
System.out.println("After~~~");
System.out.println("Set:"+set.size());
System.out.println("a: "+a);
System.out.println("b: "+b);
System.out.println("c: "+c);
}
public static void myReturn(HashSet<Integer> set, Alphabet alphabet, Integer a, Double b, int c){
set.add(new Integer(2));
alphabet = new Alphabet();
a = new Integer(3);
b++;
c++;
}
}
网友评论