开发者

how to pass array of strings from one class to other class with in same project in java

开发者 https://www.devze.com 2023-03-01 19:12 出处:网络
how to pass array of strings from one class to other 开发者_运维问答class with in same project in javapublic class A

how to pass array of strings from one class to other 开发者_运维问答class with in same project in java


public class A
{
    private String [] values;

    public static void main(String [] args)
    {
        A test = new A(args);
        String [] values = test.getValues();  // Do whatever you want with them from here
    }

    public A(String [] values)
    {
        this.values = createDuplicate(values);
    }

    public String [] getValues()
    {
        String [] duplicate = createDuplicate(this.values);

        return duplicate;
    }

    private static String [] createDuplicate(String [] values)
    {
        String [] duplicate = new String[values.length];
        System.arraycopy(values, 0, duplicate, 0, values.length);
    }
}
0

精彩评论

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