美文网首页
More than one return parameters

More than one return parameters

作者: Shiki | 来源:发表于2014-08-20 21:50 被阅读0次

    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++;
            }
    
      }
    

    相关文章

      网友评论

          本文标题:More than one return parameters

          本文链接:https://www.haomeiwen.com/subject/ihoetttx.html