Code Monkey home page Code Monkey logo

stage1-module4-collections-task1-list's Introduction

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"]

stage1-module4-collections-task1-list's People

Contributors

hopenadyahope avatar bogdanovadiana avatar symbatdeveloper avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.