0
我TreeSet的<>從一個ArrayList中獲得獨特的價值觀,並建立所有的獨特的價值觀,但得到這樣的:TreeSet中定製Android中Java的
Set<String> uniqueCategories; // declared globally
Checkout checkOut;
String strCategories = null;
.......
public void getDataFromDatabase() {
ArrayList<Checkout> detailArrayListFromDB = serviceDatabase.getCheckOut();
uniqueCategories = new TreeSet<>();
for (int i = 0; i < detailArrayListFromDB.size(); i++) {
String strCategory = detailArrayListFromDB.get(i).getCategory();
checkOut = new Checkout();
checkOut.setCategory(strCategory);
checkOutArrayList.add(checkOut);
uniqueCategories.add(checkOut.getCategory());
}
// name of unique categories
strCategories = uniqueCategories.toString();
System.out.println(strCategories);
Log.d("categories:", strCategories);
}
:
[Cars, Bikes]
我這樣試過
但我想它是這樣的:Cars, Bikes
還有一件事,我該怎麼讓上面這樣的字符串:
Cars
Bikes
這似乎更像是一個格式化你的代碼輸出 – SacJn