我傳遞了兩個系列的數據(冒號sperated :)一種方法,並期望將我的自定義類CountryDTO爲什麼在這種情況下數據沒有被設置到List對象中?
內設置這是我CountryDTO類
public class CountryDTO {
public CountryDTO(String a , String b , String c)
{
}
public String value1;
public String value2;
public String value3;
// setters and getters
}
This is my Main class
public class Test {
public static void main(String args[]) throws Exception {
Test test = new Test();
List list = (List) test.extract("IND,US,UK : WI,PAK,AUS");
Iterator itr = list.iterator();
while (itr.hasNext()) {
CountryDTO ind = (CountryDTO) itr.next();
System.out.println(ind.getValue1());
}
}
public List<CountryDTO> extract(final String v) throws Exception {
String[] values = v.split(":");
List<CountryDTO> l = new ArrayList<CountryDTO>();
for (String s : values) {
String[] vs = s.split(",");
l.add(new CountryDTO(vs[0], vs[1], vs[2]));
}
return l;
}
}
發生了什麼是空的是,我得到的輸出(CountryDTO沒有被設置)
誰能幫我
是的,這個工作,非常感謝。 – Pawan 2012-08-13 10:17:42
接受答案,如果它的工作。 – duffymo 2012-08-13 10:18:09