Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
我有一个 Integer 类型的 ArrayList,是否可以在其中存储一个值(例如:1.25)而不必将其转换为 int 从而丢失小数点后的位?
不,您不能在ArrayList<Integer>不损失精度的情况下存储双打。但是,您可以将它们存储在ArrayList<Double>.
ArrayList<Integer>
ArrayList<Double>
改为使用ArrayList<Number>。通过这种方式,您将能够存储Double和Integer实例,因为这两个类都派生自Number类。
ArrayList<Number>
Double
Integer
Number