I have an object, with this attributes:
public class Club {
private String name;
private ArrayList<Integer> points;
private int average;
Club(String name, ArrayList<Integer> points, int average){
this.name = name;
this.points = new ArrayList<>();
this.average = average;
I try to fill the arraylist with points with data from a txt file:
while((currentLine = br.readLine()) != null){
String name;
ArrayList<Integer> points = new ArrayList<>();
int average;
String[] clubData = currentLine.split(",");
name = clubData[0];
int score2 = Integer.parseInt(clubData[2]);
int score3 = Integer.parseInt(clubData[3]);
int score4 = Integer.parseInt(clubData[4]);
int score5 = Integer.parseInt(clubData[5]);
points.add(score2);
points.add(score3);
points.add(score4);
points.add(score5);
average = points.stream().mapToInt(Integer::intValue).sum()/4;
Club club = new Club(name, points, average);
When I print the objects, I get this:
Name: Clubname Points: [] Average: 6
So, the values of the file are saved in the list. Because the average (6) is calculated, and this is the good value. But, the list 'points' of the object itself is empty. Can anyone explain me this?