I'm having trouble wrapping my head around a concept. I'm trying to convert a ArrayList<String>
to a List
(or List<String>
), but I keep running into a cast exception. Yes I saw the code to convert a string array to a list, but I feel this a different scenario. my relevant code is here, please note the declarations are because I'm using GWT and thus have to declare some things as static and final...
private static List<String> values;
Ioma.dataservice.getPendingOrders(new AsyncCallback<ArrayList<Order>>(){
@Override
public void onFailure(Throwable caught) {
// TODO Auto-generated method stub
}
@Override
public void onSuccess(ArrayList<Order> result) {
ArrayList<String> orderNumbers = new ArrayList<String>();
//problem here, cannot cast arraylist<string> to list string for some reason? idk. SO it maybe?
for(int i=0;i<result.size();i++){
System.out.println("ordernumber: " + result.get(i).getOrderNumber());
System.out.println("arraysize: " + result.size());
orderNumbers.add(Integer.toString(result.get(i).getOrderNumber()));
}
for (int i=0; i<orderNumbers.size();i++){
values.add(orderNumbers.get(i));
}
cellList.setRowData(values);
}
});
basically I'm trying to create a cellList which wants a List as input. I get an arrayList of orders from a DB query and then iterate through to pull out order numbers which I then put into a arrayList, which I then want to convert to a List to use in cellList. Can someone explain why I can't do this and what the proper method should be?
I don't understand the problem you have since an ArrayList
implements a List
with List
being an interface.
You can change this line
ArrayList<String> orderNumbers = new ArrayList<String>();
to:
List<String> orderNumbers = new ArrayList<String>();
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With