Implement the program which gets List<String>
as parameter and creates a new ArrayList<String>
. ArrayList<String>
should consist of duplicated words whose index in List<String>
is divisible by 3 (indexes start from 1).
public class ArrayListCreator {
public ArrayList<String> createArrayList(List<String> sourceList) {
}
}
Input
[The, ArrayList, class, has, many, useful, methods]
Output
[class, class, useful, useful]
Implement the program which will create LinkedList<Integer>
from List<Integer>
following the rule:
If the number from the List<Integer>
is odd, then insert this number at the beginning of the LinkedList<Integer>
,
otherwise, insert the number at the end of the LinkedList<Integer>
.
public class LinkedListCreator {
public LinkedList<Integer> createLinkedList(List<Integer> sourceList) {
}
}
Input
[2, 14, 3, 6, 5, 7]
Output
[7, 5, 3, 2, 14, 6]
Implement the program which gets the List
and sorts it in ascending order of function 5x^2+3
, where x
is element
from List
. If the function value is the same for multiple elements, those elements are sorted in ascending order.
List
consists of int numbers represented as a String
. Use a Comparator
for sorting.
public class ListSorter {
public void sort(List<String> sourceList) {
}
}
class ListComparator implements Comparator<String> {
@Override
public int compare(String a, String b) {
}
}
Input
["-5", "-12", "0", "20", "9", "-20", "37"]
Output
["0", "-5", "9", "-12", "-20", "20", "37"]