【发布时间】:2018-06-22 05:41:05
【问题描述】:
我在用 Java 显示 ArrayList 的元素时遇到问题。当从 Views 调用 ArrayList 时返回 ArrayList 到现在包含虚拟值的 BMIAnalyzier 类。它显示
[]
[]
运行 java 文件时。
-
Views.java
Switch(choice[0]){ case 1: //Option 1 to display the data fo subject of given subject id. ArrayList<Records> arraylist = analyzier.find(choice[1]); System.out.println(ArrayList); Break; Case 2: //Option 2 to display the data fo subject from the range given of BMI. ArrayList<Records> arraylistList = analyzier.find(Double.parseDouble(choice[1]),Double.parseDouble(choice[2])); for (int i = 0; i < arraylistList.size(); i++){ System.out.println((arraylistList.get(i)).toString()); } Break; default: System.out.println("wrong input"); } -
BMIAnalyzier.java
public class BMIAnalyzier { public Records find(String sid) { System.out.println(new Records(sid, 0.0, 0.0, 0.0, "none")); return new Records(sid, 0.0, 0.0, 0.0, "none"); } public ArrayList<Records> find(double bmi1, double bmi2) { ArrayList<Records> alr = new ArrayList<>(); alr.add(new Records("S01", 0.0, 0.0, 0.0, "none")); alr.add(new Records("S02", 0.0, 0.0, 0.0, "none")); return alr; } } -
Records.java
public class Records extends ArrayList<Records> { private String SubjectId; private Double height; private Double width; private Double bmianalyzier; private String categories; public ArrayList <Records> list =new ArrayList<>(); public Records(String sid, Double h, Double w, Double bmi, String c) { } //getter ans setter methods. }
输出:
【问题讨论】:
-
来吧,如果你懒得格式化你的代码并使你的问题可读,你为什么认为我们可以费心回答/帮助你?
-
显然是空的。
-
你的 Break 和 Switch 命令如何工作.. 我想知道 ??
标签: java arraylist command-line