Skip to content
Advertisement

Get element value from a POJO List

I have the following POJO.

@Data
@NoArgsConstructor
@AllArgsConstructor
public class Notas {
    private int id;
    private String name;
    private Long delta;
}

And I create new indexes in the POJO my adding it.

private static final List<Notas> arrayNotas = new ArrayList<>();
arrayNotas.add(new Notas(1,"John",20L));
arrayNotas.add(new Notas(2,"Carol",40L));
arrayNotas.add(new Notas(3,"Peter",30L));

How can I have access to any index element once created? How I would be able to access the 3rd element from 3rd row?

Advertisement

Answer

First go to the 3rd element,

then go the specific field that you want to access.

in this case. it would be arrayNotas.get(2).getDelta()

Advertisement