-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathListActions.java
More file actions
27 lines (23 loc) · 846 Bytes
/
ListActions.java
File metadata and controls
27 lines (23 loc) · 846 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
import java.util.ArrayList;
/**
* Used to implement method regarding to actions on lists.
* @author Yossi Maatook.
*/
public class ListActions {
/**
* Receives a list of strings and returns the same list, but without duplicates.
* @param list - the list which we want to remove duplicates from.
* @return a list of string without duplicates.
*/
public ArrayList<String> removeDuplicates(ArrayList<String> list) {
ArrayList<String> newList = new ArrayList<>();
//Goes through the list and add the string to a new list, if doesnt exist already//
for (String s:list) {
//In case current string isn't in the list, adds it//
if (!newList.contains(s)) {
newList.add(s);
}
}
return newList;
}
}