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

Popular posts from this blog

assembly - 8086 TASM: Illegal Indexing Mode -

Java, LWJGL, OpenGL 1.1, decoding BufferedImage to Bytebuffer and binding to OpenGL across classes -

javascript - addthis share facebook and google+ url -