javaiterator类型转换_Java对数据类型转换常⽤操作操作(⼀):功能:⽤左字符串,右字符串修饰的字符串或字符串容器
//返回⼀个⽤左字符串,右字符串修饰的字符串
publicString StringAdd(String info,String left,String right)
{return left+info+right;
}//⽤左字符串,右字符串修饰字符串容器
public List StringListAdd(ListinfoList,String left,String right)
{int num=infoList.size();
List ls=new ArrayList();for(int i=0;i
{
ls.add((i)+right);
}returnls;
}
操作(⼆):功能:将容器组合成⼀个字符串,并且字符串和字符串之间添加decorate
//将字符串容器组合成⼀个字符串,并且字符串和字符串之间添加decorate
public String StringListIntoString(ListinfoList,String decorate)
{
String result=newString();int num=infoList.size();for(int i=1;i
{
result+=(i);
}if(num>0)
(0)+result;returnresult;
}//将整型容器组合成⼀个字符串,并且整型和字符串之间添加decorate
public String IntegerListIntoString(ListinfoList,String decorate)
{
String result=newString();int num=infoList.size();for(int i=1;i
{
result+=(i);
}if(num>0)
(0)+result;returnresult;
}
操作(三):功能:字符串匹配正则表达式
//判断字符串是否符合正则表达式(全匹配)
public booleanStringIsSuitExep(String str,String exp)
{boolean isMatch =Pattern.matches(exp, str);returnisMatch;
}//判断字符串是否符合正则表达式(匹配⼦字符串)
public booleanStringIsSuitSubExep(String str,String exp)
{//编译正则表达式
Pattern pattern =pile(exp);//忽略⼤⼩写的写法//Pattern pat = pile(regEx, Pattern.CASE_INSENSITIVE); Matcher matcher =pattern.matcher(str);//查找字符串中是否有匹配正则表达式的字符/字符串
boolean rs =matcher.find();returnrs;
}
//获得字符串中的符合正则表达式的值 返回结果为List
public ListgetExpString(String exp,String str)
{
Pattern pile(exp);
Matcher matcher=pattern.matcher(str);
List result=new ArrayList();
while(matcher.find()) {
result.up());
} returnresult;
}
//将字符串中符合正则表达式的字符替换为空
public List StringListReplaceAll(Listinfos,String exp)
{
List result=new ArrayList();
int g_size=infos.size();
for(int i=0;i
{
String (i).replaceAll(exp, "");
result.add(temp);
} returnresult;
}
//以对应正则表达式分隔字符并且将分隔后的字符串储存进字符串容器中
public List> StringSplitByExpToStringList(List strlist,String exp)
{
List> strresult=new ArrayList>();
int g_size=strlist.size();
for(int i=0;i
{
String (i);
if(list==null||list.equals(""))
continue;
String []strnlist=list.split(exp);
strresult.add(StringNlistToStringList(strnlist));
}
return strresult;
}
/
/以对应正则表达式分隔字符并且将分隔后的字符串储存进类容器中
public List StringSplitByExpToTList(List strlist,String exp,String []namelist,Class clazz) {
List tresult=new ArrayList();
int g_size=strlist.size();
for(int i=0;i
{
String (i);
if(list==null||list.equals(""))
continue;
String []nlist=list.split(exp);
if(nlist.length
{
throw new IllegalArgumentException("The Length of namelist is longer than nlist");
}
T bean;
try {
bean = wInstance();
int num=namelist.length;
for(int j=0;j
{
Field fs=getDeclaredField(bean, namelist[j]);
if(fs==null){
throw new IllegalArgumentException("Could not find field["+
namelist[j]+"] on target ["+bean+"]");
}
makeAccessiable(fs);
try{
fs.t(bean, (Object)nlist[j]);
}
catch(IllegalAccessException e){
System.out.println("不可能抛出的异常");
}
}
tresult.add(bean);
} catch (InstantiationException | IllegalAccessException e1) {
// TODO ⾃动⽣成的 catch 块
e1.printStackTrace();
}
}
return tresult;
}
//以对应正则表达式分隔字符并且将分隔后的字符串储存进类容器中(⾃动型) public List StringSplitByExpToTList(List strlist,String exp,Class clazz) {
List tresult=new ArrayList();
int g_size=strlist.size();
for(int i=0;i
{
String (i);
if(list==null||list.equals(""))
continue;
String []nlist=list.split(exp);
Field[ ] fields = DeclaredFields( );
T bean;
try {
bean = wInstance();
// 循环遍历字段,获取字段相应的属性值
int j=0;
for ( Field field : fields )
{
// 假设不为空。设置可见性,然后返回
field.tAccessible( true );
try
{
Field fs=getDeclaredField(bean, Name( ));
if(fs==null){
throw new IllegalArgumentException("Could not find field["+
}
makeAccessiable(fs);
try{
fs.t(bean, (Object)nlist[j]);
}
catch(IllegalAccessException e){
System.out.println("不可能抛出的异常");
}
// 设置字段可见,就可以⽤get⽅法获取属性值。
//result += ( o ) +" ";
++j;
}
catch ( Exception e )
{
// System.out.println("error--------"+methodName+".Reason is:"+e.getMessage()); }
}
tresult.add(bean);
} catch (InstantiationException | IllegalAccessException e1) {
// TODO ⾃动⽣成的 catch 块
e1.printStackTrace();
}
}