Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

ArrayList to user defined class array

Tags:

java

arrays

list

I have a List<User> userList need to convert to UserData[]

for(int i = 0; i < userList.size(); i++){
    userData[i] = userList.get(i);
}

It always returns null though the list size is 1. can anyone help on this.

like image 591
Rathishkumar Avatar asked Mar 19 '26 20:03

Rathishkumar


1 Answers

Collections can be converted to arrays:

UserData[] userArray = userList.toArray(new UserData[userList.size()])
like image 128
Ted Cassirer Avatar answered Mar 21 '26 08:03

Ted Cassirer



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!