java List methods code example

Example 1: java list

import java.util.*;
var list = new ArrayList<String>();
list.add("Hello World!");

Example 2: list in java

LIST: Can store duplicate values,
      Keeps the insertion order. 
      It allows multiple null values, 
      Also we can read a certain value by index.
- ArrayList not syncronized, array based class 
- LinkedList not synchronized, doubly linked
- Vector is synchronized, thread safe

Example 3: methods in java

A method in java is a group of statements to carry out some operation also 
known as functions.

Example 4: java methods

public class MyClass {
  static int myMethod(int x) {
    return 5 + x;
  }

  public static void main(String[] args) {
    System.out.println(myMethod(3));
  }
}
// Returns 8

Tags:

Java Example