Can someone show me how to set up getters and setters for this 2D ArrayList?
public class PureRatings {
private List<List<Integer>> pureRatingsList;
I'm not sure if this part is right...
public PureRatings() throws IOException {
pureRatingsList = parseRatingsFile();
}
Here is the code for the rest of the 2D ArrayList, I didn't know if I should include it or not...
public static List<List<Integer>> parseRatingsFile() throws IOException {
List<List<Integer>> pureRatings = new ArrayList<List<Integer>>();
BufferedReader in = new BufferedReader(new FileReader("Ratings.txt"));
String ratingsLine = null;
while ((ratingsLine = in.readLine()) != null) {
pureRatings.add(parseRatingsLine(ratingsLine));
}
in.close();
return pureRatings;
}
public static List<Integer> parseRatingsLine(String ratingsLine) throws IOException {
List<Integer> ratings = new ArrayList<Integer>();
if (ratingsLine == null) {
return ratings;
}
String[] ratingsStrArr = ratingsLine.split(" ");
try {
for (final String ratingStr : ratingsStrArr) {
ratings.add(Integer.parseInt(ratingStr));
}
} catch (NumberFormatException e) {
System.out.println(e.getMessage());
}
return ratings;
}
}
You would get an entry like this:
pureRatingsList.get(line).get(column);
You would set an entry like this:
pureRatings.get(line).set(column, newValue);
public void setPureRatingsList(List<List<Integer>> lst)
{
pureRatingsList = lst;
}
public List<List<Integer>> getPureRatingsList()
{
return Collections.unmodifiableList(pureRatingsList);
}
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.