如果您不知道数据库中 Price 的元素数量,则ArrayList最好的解决方案是List 接口的可调整大小的数组实现。创建一个ArrayListArrayList<String> yourList = new ArrayList<String>();并使用循环添加每个价格//while there is still elements from Price in database if (dataSnapshot.child("Price").getValue() != null) { Price = String.valueOf(dataSnapshot.child("Price").getValue().toString()); yourList.add(Price); ...