Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do i replace an array with an arraylist? [duplicate]

Tags:

java

How do I replace the following array with an ArrayList.

Employee[] companyTeam = {manager, engineer1, superviso1, accountant, intern };
like image 683
Sameena Avatar asked Jan 23 '14 14:01

Sameena


People also ask

How do you duplicate an ArrayList?

ArrayList cloned = new ArrayList(collection c); where c is the collection containing elements to be added to this list. Approach: Create a list to be cloned. Clone the list by passing the original list as the parameter of the copy constructor of ArrayList.

How do you replace duplicates in an array in Java?

We can remove duplicate element in an array by 2 ways: using temporary array or using separate index. To remove the duplicate element from array, the array must be in sorted order. If array is not sorted, you can sort it by calling Arrays. sort(arr) method.

Is duplicate allowed in ArrayList?

Duplicate items can be removed from the ArrayList by using a HashSet as duplicate items are not allowed in a HashSet. So the ArrayList is converted into a HashSet and that removes the duplicate items.


1 Answers

You can do something like

List<Employee> companyTeam = Arrays.asList(manager, engineer1, superviso1, accountant, intern);
like image 54
Mike B Avatar answered Oct 12 '22 23:10

Mike B