java - ArrayList Own type to String? -
hello how convert in arraylist<> string show code bad @ explaining stuff sorry:
arraylist<herniobjekt> batoh = new arraylist<>(); public void pridej(herniobjekt objekt) { batoh.add(objekt); } public void vypis() { joptionpane.showmessagedialog(null, "mas v inevtari "+batoh.); } and convert herniobject string how do that? help.
you need build string iterating through array , adding each element stringbuilder
e.g. without specifying separator....
stringbuilder sb = new stringbuilder(); (herniobjekt h : batoh) { sb.append(h); } alternatively, guava has joiner class.
joiner joiner = joiner.on("; ").skipnulls(); . . . return joiner.join("harry", null, "ron", "hermione"); in either case you should override tostring() in herniobjekt class
Comments
Post a Comment