Common methods of Java string:
Split () method;
Equals () method;
substring () method;
Example method:
private boolean isSameSelCode(Fbillconfirm fbillconfirm, HashMap outputParam){
String strExpenseID=new String();
Fbillconfirmdetail[] fbillconfirmdetail=fbillconfirm.getFbillconfirmdetail();
if(fbillconfirmdetail!=null&&fbillconfirmdetail.length>0){
for(int i=0;i<fbillconfirmdetail.length;i++){
//如果前台传的参数不为Delete状态,即需要新增或修改的数据,需要校验费用
if(!Constants.DELETED.equals(fbillconfirmdetail[i].getRowstate())){
strExpenseID+=fbillconfirmdetail[i].getFbcd_expense_id()+";";
}
}
}
//处理字符串数组传参
String[] strExpenseIDs=strExpenseID.split(";");
if(strExpenseIDs.length>0){
return EpenseSigned.checkSelCode(strExpenseIDs);
}else{
return true;
}
}
Second, Java string considerations:
1.String str= "";--point the handle to a Str object (on the stack, into the pool), string str=new string ();--Create a new object (in the team, not into the pool), the two are different.
Initialization of 2.string[] arrays: string[] The initialization of the STR array needs to define the length, otherwise it cannot be directly assigned, such as str[i]= "123" will be an error. The predefined length required for initialization. Otherwise, you are pointing directly to an existing array.
3.stra.eqauls (STRB)--stra is not nullable, otherwise null, STRA==STRB: Compares two referenced values (that is, the value of the pointer), STRA==STRB: Compares the values of two objects.
4.split Method:
public static void splitString() {
// 定义一个字符串变量
String strUser = "Zhangshan,Lisi,Wangma";
// 切割
String[] strsUser = strUser.split(",");
for (int i = 0; i < strsUser.length; i++) {
System.out.println(strsUser[i]);
}
}
Print results:
Zhangshan
Lisi
Wangma