Skip to content

symbatDeveloper/stage1-module4-collections-task1-list

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

10 Commits
 
 
 
 
 
 
 
 

Repository files navigation

Tasks

1. Create ArrayList

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) {
    }
}

Example

Input

[The, ArrayList, class, has, many, useful, methods]

Output

[class, class, useful, useful]

2. Create a LinkedList

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) {
    }
}

Example

Input

[2, 14, 3, 6, 5, 7]

Output

[7, 5, 3, 2, 14, 6]

3. List sorting

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) {
    }
}

Example

Input

["-5", "-12", "0", "20", "9", "-20", "37"]

Output

["0", "-5", "9", "-12", "-20", "20", "37"]

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • Java 100.0%