Sobes.tech
Junior — Middle

Have you used the Collections class in your projects?

sobes.tech AI

Answer from AI

Yes, the Collections class in Java is widely used for working with data collections — lists, sets, queues, etc. It provides static methods for creating, sorting, searching, and synchronizing collections.

Example of using Collections to sort a list of strings:

import java.util.*;

public class Example {
    public static void main(String[] args) {
        List<String> names = new ArrayList<>();
        names.add("Ivan");
        names.add("Anna");
        names.add("Peter");

        Collections.sort(names);

        for (String name : names) {
            System.out.println(name);
        }
    }
}

Collections also contains methods for searching elements, reversing lists, filling with values, and much more, which makes working with data easier.