Type of List to Store Multipe Data Types

前端 未结 3 1610
情话喂你
情话喂你 2021-01-13 21:22

So my problem is that I\'ve written a function that takes two Doubles, two Int, and a Calendar object on Android (Java). I believe the class provided to allow it to run in a

3条回答
  •  花落未央
    2021-01-13 21:47

    Just

    List objects = new ArrayList();
    
    
    

    or so?

    I wouldn't recommend this approach though. The data must be somehow related to each other. Why would you make it hard for yourself and mix different types of data in a collection? What do you need it for at end? Just passing it around through layers? You could also just create a custom javabean object for this (also known as value object or data transfer object). Something like:

    public class Data {
        private Double double1;
        private Double double2;
        private int int1;
        private int int2;
        private Calendar calendar;
        // Add/generate getters and setters.
    }
    

    提交回复
    热议问题