wood burning stoves*
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


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
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
Author

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.


Regards

Joseph Prabhu
Hunter McMillen
Ranch Hand

Joined: Mar 13, 2009
Posts: 492

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

Hunter


"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
Hi

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.

Regards
Joe



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?


OCJP6, OCWCD5
Dan Din
Greenhorn

Joined: Jun 06, 2011
Posts: 12
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,
D.
Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 38075
    
  22
Dan Din, welcome to the Ranch
Enrico Savazzi
Greenhorn

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:



--ES
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Concatenate method result , repeat in each Request
 
Similar Threads
String Concat
.append() method
Pls help me out to solve this question
quick question about combining variables
String Concatination