I am passing two series of data ( colon sperated 🙂 to a method and expecting that to be set inside my Custom class CountryDTO
This is my CountryDTO class
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;
}
}
What is happening is that , i am getting output as null ( CountryDTO is not being set )
Could anyone please help me
I’m sorry, but your DTO is incorrect. I think it should look like this:
I can’t speak to what else you code might be doing wrong, but this is certainly off-base.