如何从一个类与其他类在同一个项目中传递一个字符串数组中的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);
}
}
你传递数组一样你通过任何其他物体。你能举一个你想要的例子吗? – 2011-04-28 09:37:18