0

I am creating the Leg Objects this way

List<Leg> legs = new ArrayList<Leg>(legdata.length);

I need to pass this legs to an method with the below signature as shown :

 public static String getStrategy(Leg[] leg)

when i did the below way i am getting an error .

String resultData = CMPUtil.getStrategy(legs.toArray());

Also tried this way

Leg les[] = (Leg)legs.toArray();  ( It says cannot cast from Object to Leg)

could anybody please let me know , how to resolve this ??

3 Answers 3

2

try

String resultData = CMPUtil.getStrategy((Leg [])legs.toArray(new Leg[legs.size()]));
Sign up to request clarification or add additional context in comments.

1 Comment

Thank you all very much , (Unfortunately i could select only one answer)
2

Pass in an array of the right type to the other overload of List.toArray:

Leg[] legsArray = legs.toArray(new Leg[0]); // Or new Leg[legs.size()]

Comments

1

Leg les[] = legs.toArray(new Leg[legs.length]);

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.