• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Tim Cooke
  • paul wheaton
  • Liutauras Vilda
  • Ron McLeod
Sheriffs:
  • Jeanne Boyarsky
  • Devaka Cooray
  • Paul Clapham
Saloon Keepers:
  • Scott Selikoff
  • Tim Holloway
  • Piet Souris
  • Mikalai Zaikin
  • Frits Walraven
Bartenders:
  • Stephan van Hulst
  • Carey Brown

Concatenate method result , repeat in each Request

 
Ranch Hand
Posts: 162
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
 
Ranch Hand
Posts: 492
Firefox Browser VI Editor Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
We cant really help unless you post the request you are using.

Hunter
 
Bartender
Posts: 2700
IntelliJ IDE Opera
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
There is no such thing as urgent.
What is the problem that you're trying to solve?
 
joseph prabhu
Ranch Hand
Posts: 162
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Bartender
Posts: 2700
IntelliJ IDE Opera
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Please use code tags. You can edit your post with the button.
 
Ranch Hand
Posts: 144
Oracle Fedora Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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?
 
Greenhorn
Posts: 13
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
Marshal
Posts: 80093
413
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Dan Din, welcome to the Ranch
 
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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:

 
Your mother is a hamster and your father smells of tiny ads!
Smokeless wood heat with a rocket mass heater
https://woodheat.net
reply
    Bookmark Topic Watch Topic
  • New Topic