java - remove last comma of dynamic jTextFields -
i getting value of dynamically added jtextfield
using code:
edited:
component[] children = jpanel1.getcomponents(); // iterate on subpanels... (component sp : children) { if (sp instanceof subpanel) { component[] spchildren = ((subpanel)sp).getcomponents(); // iterate on jtextfields... (component spchild : spchildren) { if (spchild instanceof jtextfield) { string text = ((jtextfield)spchild).gettext(); system.out.println(text); } } } }
output text file got: text1,text2,text3,
now appeared next problem - "last comma". found guava can solve problem, due less experience couldn't implement. if possible give me advice or suggestion.
thank in advance.
use stringjoiner
:
stringjoiner joiner=new stringjoiner(","); (component spchild : spchildren) { if (spchild instanceof jtextfield) { string text = ((jtextfield)spchild).gettext(); joiner.add(text); } } outfile.write(joiner.tostring());
Comments
Post a Comment