java - Converting LinkedList to Arrary -
this question has answer here:
- convert list array in java 11 answers
i have created linkedlist
employee
object stored in it. need write method converttoarray
make array of employee
s taking linkedlist
.
any ideas?
the easiest way utilize linkedlist.toarray method
// create array , copy list employee[] array = list.toarray(new employee[list.size()]);
however, if learning , iteratively. think how declare , of items array.
first, need do?
1) declare array of employee's
in order that, know how big make array since size of array cannot changed after declaration. there method inherited list called .size()
employee[] array = new employee[list.size()]
2) each slot in array, copy corresponding element in list
to this, need utilize loop
for(int = 0; < array.length; i++) { //access element list, assign array[i] }
Comments
Post a Comment