While printing ArrayList multipe value it displays only -> '[]'

前端 未结 2 1163
無奈伤痛
無奈伤痛 2021-01-29 03:15

I have a problem with displaying the elements of the ArrayList in Java. While returning the ArrayList when its called from the Views to BMIAnalyzier cl

2条回答
  •  小鲜肉
    小鲜肉 (楼主)
    2021-01-29 03:57

    I suppose you are new to java. You need to understand the basics first. For instance in your case, ArrayList is a collection which you use to hold multiple values of the same type. With your Records class you are extending the collection which is not required here.

    public class Records extends ArrayList < Records > {

    should be

    public class Records {

    Also, you should always provide content to your class Constructor otherwise no values would be set for the object.

        public Records(String sid, Double h, Double w, Double bmi, String c) {
            this.SubjectId = sid;
           // set other values as well
        }
    

    And, find(String sid) is returning Records object

    ArrayList < Records > arraylist = analyzier.find(choice[1]);
    

    should be changed to

    Records record = analyzier.find(choice[1]);
    

    For printing the values of your Records object do as @Niklas suggested

提交回复
热议问题