How to add multiple items to the ArrayList

There are various ways to initialize an ArrayList with multiple elements and add elements to it. 1. using add() method repeatedly : ArrayList<String> str=new ArrayList<>();str.add(“banana”);str.add(“Apple”);System.out.println(str); 2. Using ArrayList.asList() method : ArrayList<String> list=new ArrayList<>(Arrays.asList(“America”,”Europe”,”Asia”));System.out.println(list); 3.Using Collections.addAll() : ArrayList<String> new_list =new ArrayList<>();Collections.addAll(new_list, “Car”,”Bike”);System.out.println(new_list); 4. Using Java Streams : ArrayList<String> another_list=Stream.of(“Lenovo”,”Dell”,”Apple”).collect(Collectors.toCollection(ArrayList::new));System.out.println(another_list) Outputs:[banana, Apple][America, Europe, Asia][Car, Bike][Lenovo, Dell, Apple]

Tuple in Python

A tuple is a built-in Python data type that represents an ordered, immutable collection of elements. Key Features:Ordered: Elements have a defined order (you can access by index). Immutable: Once created, elements cannot be changed. Allows duplicates: Same value can appear more than once. Can contain mixed data types (integers, strings, lists, etc.).

Set in Python

A set is a built-in data type in Python that represents an unordered collection of unique elements. Key Features:Unordered: The elements have no fixed position. Unique: Duplicate values are automatically removed. Mutable: You can add or remove elements. Iterable: You can loop through a set.

List in Python

A list in Python is a built-in, ordered, and mutable collection of elements. It can hold items of different data types such as integers, strings, floats, or even other lists. Key Features:Ordered: Items maintain their insertion order. Mutable: You can add, remove, or change items after the list is created. Heterogeneous: Can store mixed data…

Importing Libraries in Python

What is a Library? A library is a collection of reusable functions, classes, and modules. Python comes with many built-in libraries, and you can also use external libraries created by the Python community. Importing Built-in Libraries import mathprint(“Square root of 16 is:”, math.sqrt(16)) Output:Square root of 16 is: 4.0 Importing with an Alias Use as…