Created
May 16, 2023 16:27
-
-
Save liketaurus/396c7205030b9c18e8eb3ab077799bc4 to your computer and use it in GitHub Desktop.
Приклад простого консольного застосунку, який ілюструє використання колекцій і дженериків.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import java.util.ArrayList; | |
import java.util.List; | |
public class Main { | |
public static void main(String[] args) { | |
// Створюємо список цілих чисел | |
List<Integer> numbers = new ArrayList<>(); | |
// Додаємо елементи до списку | |
numbers.add(10); | |
numbers.add(20); | |
numbers.add(30); | |
// Виводимо елементи списку | |
System.out.println("Елементи списку:"); | |
for (Integer number : numbers) { | |
System.out.println(number); | |
} | |
// Перевіряємо розмір списку | |
System.out.println("Розмір списку: " + numbers.size()); | |
// Перевіряємо, чи список містить певний елемент | |
int element = 20; | |
if (numbers.contains(element)) { | |
System.out.println("Список містить елемент " + element); | |
} else { | |
System.out.println("Список не містить елемент " + element); | |
} | |
// Видаляємо елемент зі списку | |
numbers.remove(1); | |
// Виводимо оновлений список | |
System.out.println("Оновлені елементи списку:"); | |
for (Integer number : numbers) { | |
System.out.println(number); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment