我有一些字符串数组:String [] contact={"val1","val2","val3","phone1","phone2","phone3"};
我想将其转换为myClass,它看起来像:
Class myClass{
String val1;
String val2;
String val3;
Phones phones;
}
Class Phones{
String phone1;
int phone2;
int phone3;
}
我的问题是某些字符串值可能为空,例如:
String[] contact={"val1","val2"," ","phone1","",""};
提前致谢。!!
答案 0 :(得分:1)
我认为你想编写一个"构造函数",一个以类名作为名称的方法,取一个String [],将值赋给从它得到的参数计算的字段。