Record in Java
Java record is like a simplified class in Java. The record field is immutable. It means you can change the field after you create it. It seems to be good thing. The field access is private by default, it means you can not access the field directly such as Instead, you need to use
How to create a Person record with name and age, and how to print it out
    record Person(String name, int age){};

    Person person = new Person("David", 20);

    System.out.print("person name=" +;
    System.out.print("person age=" + person.age());
Return a Record from a method
    record Person(String name, int age){};

    static Person fun(){
        return Person("David", 20);

    // main

    Person person = fun();
How to create record that contains array
1. Create record called intArr that contains int array 2. Write a function return the record
    recrod intArr(int n, int[] arr){};

    static intArr fun(){
        int[] arr = {1, 2, 3};
        return new intArr(1, arr);

    // main
    intArr rec = fun();
    for(int i = 0; i < rec.arr().length; i++){