开发者

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

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

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜