Java linkedlist Just need in question method dont repost who

Java, linkedlist. Just need in question method, don\'t repost whole code.

Will thumb up, thanks.

(6 pts) Write a new method named toArrayList0 that returns an ArrayList object containing all elements in the calling list, in the same order (i.e., the head node\'s data should be stored in index 0 of the returned array list) Use your ArrayList class from the first part of this assignment.

Solution

public ArrayList toArrayList(){ // create an empty list ArrayList list = new ArrayList<>(); // iterate through all elements of linkedList while append each node to above defined list for(Node temp = head; temp != null; temp = temp.getNext()) list.add(temp); // return formed ArrayList return list; }
Java, linkedlist. Just need in question method, don\'t repost whole code. Will thumb up, thanks. (6 pts) Write a new method named toArrayList0 that returns an A

Get Help Now

Submit a Take Down Notice

Tutor
Tutor: Dr Jack
Most rated tutor on our site