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

python - mat is not a numerical tuple : openCV error -

c# - MSAA finds controls UI Automation doesn't -

wordpress - .htaccess: RewriteRule: bad flag delimiters -