userAnalyst
userAnalyst

Reputation: 23

java write the output in comma delimited format

How to write the below output in comma delimited format.Please help on this.

logger.info("total count of ReportGen requests with size <100kB: "+countlt200);
logger.info("# of Non-ReportGEN Requests: "+countNON);
logger.info("total response time of ReportGen requests with size >=100kB: "+gt200ReportGen);
logger.info("total response time of ReportGen requests with size <100kB: "+lt200ReportGen);
logger.info("total response time of all non ReportGen requests: "+nonReportResTime);
logger.info("total size of ReportGen requests with size <100kB: "+lt200ResTime);
logger.info("total size of ReportGen requests with size >=100kB: "+gt200ResTime);
logger.info("total size of all non ReportGen requests: "+nonReportGenSize);

Upvotes: 0

Views: 353

Answers (2)

Roman Evseenko
Roman Evseenko

Reputation: 168

You can use StringJoiner:

StringJoiner joiner = new StringJoiner(SEPARATOR);
joiner.add(value);
joiner.toString();

Upvotes: 0

kamwo
kamwo

Reputation: 2000

If I guess correctly, you want to make only one output, which is comma separated.

If you are using Java 8 you could use the String.join() method (see other post).

Or you could use a StringBuilder or just concatenation. Here an example with a StringBuilder:

StringBuilder stringBuilder = new StringBuilder();

stringBuilder.append("total count of ReportGen requests with size <100kB: "+ countlt200);
stringBuilder.append(", # of Non-ReportGEN Requests: "+countNON);
stringBuilder.append(", total response time of ReportGen requests with size >=100kB: "+gt200ReportGen);

// or if you want it more readable for you 
stringBuilder.append("something..something");
stringBuilder.append(",");
stringBuilder.append("something..something");
stringBuilder.append(",");

// aso

logger.info(stringBuilder.toString());

Upvotes: 2

Related Questions