Skip to main content
added 3 characters in body
Source Link

A couple of alternate options here - any of such can simply only resolve to making the intentions clear, although it's hardly an issue.

It might be a little clearclearer, albeit nonot much, using lastIndexOf:

String withoutLastComma = result.substring(0, result.lastIndexOf(",")); 

Or just refactor a little, which could be more explanatory:

StringBuilder result = new StringBuilder(); for (int i = 0; i < paramList.size(); i++) { result.append(paramList.get(i)); if (i + 1 != paramList.size()) result.append(", "); } System.err.println(result); 

Or, lastly, use a string utility library as linked in other answers provided; though, the thought of doing so brings the term 'sledgehammer to crack a nut' to mind, but it might well be justified depending on what other operations you require to carry out.

A couple of alternate options here - any of such can simply only resolve to making the intentions clear, although it's hardly an issue.

It might be a little clear, albeit no much, using lastIndexOf:

String withoutLastComma = result.substring(0, result.lastIndexOf(",")); 

Or just refactor a little, which could be more explanatory:

StringBuilder result = new StringBuilder(); for (int i = 0; i < paramList.size(); i++) { result.append(paramList.get(i)); if (i + 1 != paramList.size()) result.append(", "); } System.err.println(result); 

Or, lastly, use a string utility library as linked in other answers provided; though, the thought of doing so brings the term 'sledgehammer to crack a nut' to mind, but it might well be justified depending on what other operations you require to carry out.

A couple of alternate options here - any of such can simply only resolve to making the intentions clear, although it's hardly an issue.

It might be a little clearer, albeit not much, using lastIndexOf:

String withoutLastComma = result.substring(0, result.lastIndexOf(",")); 

Or just refactor a little, which could be more explanatory:

StringBuilder result = new StringBuilder(); for (int i = 0; i < paramList.size(); i++) { result.append(paramList.get(i)); if (i + 1 != paramList.size()) result.append(", "); } System.err.println(result); 

Or, lastly, use a string utility library as linked in other answers provided; though, the thought of doing so brings the term 'sledgehammer to crack a nut' to mind, but it might well be justified depending on what other operations you require to carry out.

Source Link

A couple of alternate options here - any of such can simply only resolve to making the intentions clear, although it's hardly an issue.

It might be a little clear, albeit no much, using lastIndexOf:

String withoutLastComma = result.substring(0, result.lastIndexOf(",")); 

Or just refactor a little, which could be more explanatory:

StringBuilder result = new StringBuilder(); for (int i = 0; i < paramList.size(); i++) { result.append(paramList.get(i)); if (i + 1 != paramList.size()) result.append(", "); } System.err.println(result); 

Or, lastly, use a string utility library as linked in other answers provided; though, the thought of doing so brings the term 'sledgehammer to crack a nut' to mind, but it might well be justified depending on what other operations you require to carry out.