-2
我有一個POJO類名爲「性能」這樣如何ArrayList的由POJO類的轉換成數組中的java
public class Performance {
String productId;
String productBrand;
String productGraph;
//getters and setters
我保存它的ArrayList名爲「performanceList」是這樣的:
JSONArray dataGraph=null;
JSONObject obj = new JSONObject(response);
dataGraph = obj.getJSONArray("product_list");
performanceList.clear();
for(int i=0;i<dataGraph.length(); i++){
JSONObject jsonObject = dataGraph.getJSONObject(i);
Performance performance = new Performance();
if(!jsonObject.isNull("id")){
performance.setProductId(jsonObject.getString("id"));
}
if(!jsonObject.isNull("brand")) {
performance.setProductBrand(jsonObject.getString("brand"));
}
if(!jsonObject.isNull("sales")){
performance.setProductGraph(jsonObject.getString("sales"));
}
performanceList.add(i, performance);
}
而現在,你能不能幫我從ArrayList中獲取數據,並轉換成數組就這樣
String []brand = {/*getProductBrand from arraylist*/};
String []id = {/*getProductId from arraylist*/};
String []id = {/*getProductGraph from arraylist*/};
OP想要檢索的陣列的任何其他數據,因此你可以這樣做:String [] brand = performances.stream()。map(Performance :: getProductBrand).toArray(String [] :: new);' –