java - trimming a string plus checking if string is not empty -
i have array list in objects stored, , object's getters string value shown below
list<abcd> hgfer = (list<abcd>)getter.rows(jhfile); for(abcd f: hgfer) { string p = f.getfromarea()
as shown above array list , values extracting. have make sure string getting not empty plus should trimmed, achieved shown below:
p.getfromarea().trim().length() > 0
now there several getters attached object return string. every individual string have this. thinking make separate individual method return boolean value , string parameter pass.for ex:
private string validaterow(string g) { boolean valid = false;' try{ **//code check should not empty plus should trim one** } catch(){} valid = false; }
and have make call method somewhere within class
list<abcd> hgfer = (list<abcd>)getter.rows(jhfile); for(abcd f: hgfer) { if (!validaterow(f.getfromarea()) {//customised message } else continue;
now please advise how achieve string should not empty plus should trim one
you can try this:-
public boolean isnullorempty(string str) { return (str == null) || (str.trim().length() == 0); }
this return true
if string
null
or empty
, else false
.
Comments
Post a Comment