java - Converting LinkedList to Arrary -


this question has answer here:

i have created linkedlist employee object stored in it. need write method converttoarray make array of employees 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

Popular posts from this blog

javascript - ScrollTo Effect (href to div) -

javascript - ng-class not responding to change in model in Angular? -

javascript - document.registerElement extending HTMLInputElement prototype while using custom tag name to avoid implicit browser style -