Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.java.programmer > #23032

Re: Printing Out appended list

NNTP-Posting-Date Thu, 21 Mar 2013 10:22:14 -0500
Date Thu, 21 Mar 2013 15:22:13 +0000
From lipska the kat <"nospam at neversurrender dot co dot uk">
Organization Trollbusters 3
User-Agent Mozilla/5.0 (X11; Linux x86_64; rv:11.0) Gecko/20120410 Thunderbird/11.0.1
MIME-Version 1.0
Newsgroups comp.lang.java.programmer
Subject Re: Printing Out appended list
References <47637551-543f-49fc-8165-41de869e6a8f@googlegroups.com>
In-Reply-To <47637551-543f-49fc-8165-41de869e6a8f@googlegroups.com>
Content-Type text/plain; charset=ISO-8859-1; format=flowed
Content-Transfer-Encoding 8bit
Message-ID <ad-dnaSVvNk7uNbMnZ2dnUVZ8madnZ2d@bt.com> (permalink)
Lines 42
X-Usenet-Provider http://www.giganews.com
X-AuthenticatedUsername NoAuthUser
X-Trace sv3-b943229gmmyVOH88Ts47JfHitC+tWWeEV6eEjJ/jJNjTnB9cecyjgEKNH9eTu33qLLfhIYQS/ABp/9j!qC7yPY6v2/fBAPSef2q+5NRNQOmCYvaadDML7fXNHV8btW/yqSng4S2z1HVSiEXAbxt5Fucn01w=
X-Complaints-To abuse@btinternet.com
X-DMCA-Complaints-To abuse@btinternet.com
X-Abuse-and-DMCA-Info Please be sure to forward a copy of ALL headers
X-Abuse-and-DMCA-Info Otherwise we will be unable to process your complaint properly
X-Postfilter 1.3.40
X-Original-Bytes 2456
Path csiph.com!usenet.pasdenom.info!news.stben.net!border3.nntp.ams.giganews.com!Xl.tags.giganews.com!border1.nntp.ams.giganews.com!nntp.giganews.com!local2.nntp.ams.giganews.com!nntp.bt.com!news.bt.com.POSTED!not-for-mail
Xref csiph.com comp.lang.java.programmer:23032

Show key headers only | View raw


On 21/03/13 14:59, subhabangalore@gmail.com wrote:
> Dear Group,
>
> If I try to append the strings in sb within a loop, where strings are getting generated from loop,
> this part is getting fine, but the problem is how I can take out the print of the "sb" portion.
>
>   for (loop condition) {
>      StringBuilder sb = new StringBuilder();
>      sb.append("some string");
>      . . .
>      sb.append(anotherString);
>      }

Difficult to know exactly what you mean here but I'll take a shot

StringBuilder sb = new StringBuilder();
for(condition){
    sb.append("some string");
    ...
}
System.out.printf("%s\n", sb.toString());

--or, slightly more disturbingly --

StringBuilder buffer = new StringBuilder();
for(condition){
    StringBuilder sb = new StringBuilder();
    sb.append("whatever");
    ...
    buffer.append(sb.toString());
}
System.out.printf("%s\n", buffer.toString());

can't see the point of this second example although it appears to meet 
your original criteria of creating a new builder for each iteration of 
the loop.

lipska

-- 
Lipska the Kat©: Troll hunter, sandbox destroyer
and farscape dreamer of Aeryn Sun

Back to comp.lang.java.programmer | Previous | NextPrevious in thread | Next in thread | Find similar | Unroll thread


Thread

Printing Out appended list subhabangalore@gmail.com - 2013-03-21 07:59 -0700
  Re: Printing Out appended list markspace <markspace@nospam.nospam> - 2013-03-21 08:09 -0700
  Re: Printing Out appended list lipska the kat <"nospam at neversurrender dot co dot uk"> - 2013-03-21 15:22 +0000
  Re: Printing Out appended list Eric Sosman <esosman@comcast-dot-net.invalid> - 2013-03-21 11:56 -0400
    Re: Printing Out appended list Roedy Green <see_website@mindprod.com.invalid> - 2013-03-21 18:21 -0700
  Re: Printing Out appended list Roedy Green <see_website@mindprod.com.invalid> - 2013-03-21 14:06 -0700

csiph-web