Question:

How should I pass array of objects to a method in JAVA code ?

by  |  earlier

0 LIKES UnLike

I got string from a property file. I have to pass it to a method. But that method ask for an array of objects as input. So how should I pass that string as an array of object ?

 Tags:

   Report

3 ANSWERS


  1. If I understand your question, you receive a single String object from the request against your property file. Create String[] (array) of length one and stuff your property file String into it.

    String[] strArray = new String[1];

    strArray[0] = your_property_string;

    Pass strArray as the argument to the method that requires an Object[] - a String array IS AN Object array.


  2. I answered your last question where you didn't say anything about an object array.  If you only have one string, it would be pointless to pass it as an array of objects.  But if your String is long and from a multi-line file, you could take each line and use that for each entry in your array.

  3. You're doing something wrong.

Question Stats

Latest activity: earlier.
This question has 3 answers.

BECOME A GUIDE

Share your knowledge and help people by answering questions.