Java

Need to learn my basic Java syntax for learning Hadoop.

For loops

for (int i = 0; i < 5; i++) {
    System.out.println(i);
}

Arrays

int[] numbers = new int[5]; // Array of 5 integers
numbers[0] = 10;            // Assign value to first element
 
int[] values = {1, 2, 3, 4, 5}; // Array initialization
System.out.println(values[2]);   // Prints: 3

The List interface is a part of the Java Collections Framework. It extends the Collection interface and provides methods to work with ordered elements (sequence). The two most popular implementations of the List interface are:

  • ArrayList: A dynamic array that can grow in size.
  • LinkedList: A doubly-linked list which allows for fast insertions and deletions.

List

import java.util.ArrayList;
import java.util.List;
 
List<String> arrayList = new ArrayList<>();
 
arrayList.add("Alice");    // Adding elements
arrayList.add("Bob");
arrayList.add("Charlie");
 
System.out.println(arrayList.get(1));  // Accessing elements (Bob)
arrayList.remove(1);                   // Removing element at index 1 (Bob)
System.out.println(arrayList);         // [Alice, Charlie]