This week's book giveaway is in the OO, Patterns, UML and Refactoring forum.
We're giving away four copies of Refactoring for Software Design Smells: Managing Technical Debt and have Girish Suryanarayana, Ganesh Samarthyam & Tushar Sharma on-line!
See this thread for details.
The moose likes Java in General and the fly likes Concatenate method result , repeat in each Request Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

JavaRanch » Java Forums » Java » Java in General
Bookmark "Concatenate method result , repeat in each Request" Watch "Concatenate method result , repeat in each Request" New topic

Concatenate method result , repeat in each Request

joseph prabhu
Ranch Hand

Joined: Feb 26, 2008
Posts: 162
Hi All,

I use some some string concatenation(plus operator or concat method) Using String class. and have final output and it is return to jsp. Whenever new request is made the results of concat method alone get repeated for each request. How can be overcome this? Please suggest it is very urgent.


Joseph Prabhu
Hunter McMillen
Ranch Hand

Joined: Mar 13, 2009
Posts: 492

We cant really help unless you post the request you are using.


"If the facts don't fit the theory, get new facts" --Albert Einstein
Wouter Oet
Saloon Keeper

Joined: Oct 25, 2008
Posts: 2700

There is no such thing as urgent.
What is the problem that you're trying to solve?

"Any fool can write code that a computer can understand. Good programmers write code that humans can understand." --- Martin Fowler
Please correct my English.
joseph prabhu
Ranch Hand

Joined: Feb 26, 2008
Posts: 162

My code is below

see the second for loop , i am using concat method and concatenning the ""," to the individual string and final string is set in a request attribute and in jsp using that attribute and printing in browser.

Can some body help.


that "","" is concatenning to final results at every request in browser i made. It is very strange.
Wouter Oet
Saloon Keeper

Joined: Oct 25, 2008
Posts: 2700

Please use code tags. You can edit your post with the button.
Mike Zal
Ranch Hand

Joined: May 04, 2011
Posts: 144

This looks like exact thing the StringBuilder class and append method was designed for.

EDIT: you never said what was wrong with your code. Can you provide some example of your inputs, intended outputs, and actual outputs?

Dan Din

Joined: Jun 06, 2011
Posts: 13
My guess: you try to eliminate the spaces between words separated by commas - if so, you need a jsonPData initialization after splitting into array.
Good luck,
Campbell Ritchie

Joined: Oct 13, 2005
Posts: 43905
Dan Din, welcome to the Ranch
Enrico Savazzi

Joined: Jan 01, 2007
Posts: 7
I also have trouble understanding what you are trying to accomplish. In any case, assuming that

(note that some of the spaces are repeated multiple times) your code produces the output:
:This, is , a , test.This","is","a","test.
To me, it looks like the code does exactly what I would expect it to do, i.e. splits the original string into a string array on commas, strips away the leading and trailing spaces of each array element (first for loop), appends "," to each element array but the last (second for loop), and finally tacks all element arrays onto the original string (third for loop).

Assuming you want instead to produce "This","is","a","test." simply do:

I’ve looked at a lot of different solutions, and in my humble opinion Aspose is the way to go. Here’s the link:
subject: Concatenate method result , repeat in each Request
It's not a secret anymore!