0

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

1
  • You pass arrays just like you pass any other object. Could you give a example of what you want? Commented Apr 28, 2011 at 9:37

1 Answer 1

1
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);
    }
}
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.