This week's giveaway is in the Android forum.
We're giving away four copies of Android Security Essentials Live Lessons and have Godfrey Nolan on-line!
See this thread for details.
The moose likes Beginning Java and the fly likes modify the arrray to string 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 » Beginning Java
Bookmark "modify the arrray to string" Watch "modify the arrray to string" New topic

modify the arrray to string

Rajesh Veluchamy
Ranch Hand

Joined: Jan 15, 2008
Posts: 47
str[] array contains some data like str[]={"12","13","345"}

Now i want str1='12','13','345'
but i am getting a space between number and quotes(')
i.e,--> '12 ','13 ','345'

one more thing, i am not getting space in the last number(345)

[ March 13, 2008: Message edited by: Rajesh Veluchamy ]

-Rajesh.V<br /> Software Consultant
Rob Spoor

Joined: Oct 27, 2005
Posts: 19656

I don't know what you did because if I try your code I get '12','13','345' just as you want. I used your exact code with the addition of the declaration:

[ March 13, 2008: Message edited by: Rob Prime ]

How To Ask Questions How To Answer Questions
Henry Wong

Joined: Sep 28, 2004
Posts: 18552

Just wrote a quick test program, with your loop, and your test data. It ran fine. I'm not getting any extraneous spaces.


Books: Java Threads, 3rd Edition, Jini in a Nutshell, and Java Gems (contributor)
Ernest Friedman-Hill
author and iconoclast

Joined: Jul 08, 2003
Posts: 24183

As you're not adding spaces in yourself, they must be in the original data. You might try


[Jess in Action][AskingGoodQuestions]
Neha Agarwal

Joined: Mar 12, 2008
Posts: 16
public class Test {
public static void main(String[] args) {
String str[]={"12","13","345"};
StringBuffer str1 = new StringBuffer();
for (int ii = 0; ii < str.length; ii++)
if(ii==(str.length-1)) {


Ben Souther

Joined: Dec 11, 2004
Posts: 13410

"Neha Java",
Please check your private messages.

Java API J2EE API Servlet Spec JSP Spec How to ask a question... Simple Servlet Examples jsonf
It is sorta covered in the JavaRanch Style Guide.
subject: modify the arrray to string
Similar Threads
doubt in a program of convert decimal to Hexadecimal-please clarify
String Handling
equals() and ==, doubt (while getting data from an url)
The well known String str = "abc" and String str1 = new String("abc");