/* I am writing this class to see the output of:
args.toString();
I want to see if the toString() method on the String[] will convert
the array contents into one string or it will write out it's type
name,
i.e. the <code>Class</code> class' name.
As observed, the output is
[java.lang.String@1693e2;
which looks like the array's underlying type's name and the starting
memory address.
*/
public class Ats /*implying Array To String */
{
public static void main(String[] args)
{
if ( args.length == 0 )
System.out.println("Usage: ats arg1 [arg2 [arg3...]]");
else
System.out.println(args.toString());
}
}
Sathyaish - 05 Apr 2007 15:57 GMT
*RESOLVED*
I am using jsdk 1.4.2, in which there is no method to convert an array
to a string. We have to do it manually.
>From v1.5.x onwards, there is a toString() override in
java.utils.Arrays class that does it.
http://java.sun.com/j2se/1.5.0/docs/api/java/util/Arrays.html#toString(java.lang
.Object[])
Sathyaish - 05 Apr 2007 16:10 GMT
It is amazing that java.lang.String class has a split method but no
reverse mechanism for joining, like the "join" method some languages
such as VB/VB.NET and the .NET framework support.
http://java.sun.com/j2se/1.4.2/docs/api/java/lang/String.html#split(java.lang.String)
Sathyaish - 05 Apr 2007 16:28 GMT
Hi! :-)
My question was if there was a way to convert a String[] to a String.
I wa writing small programs to try these basic things out and
documenting them also for other users' benfit and for my own record
sake.
When I document things I am learning, I am able to retain them for
longer and revisit them as and when I forget them.
:-)
Hope you are not angry about it? :-)
Oliver Wong - 05 Apr 2007 17:27 GMT
> Hi! :-)
>
[quoted text clipped - 9 lines]
>
> Hope you are not angry about it? :-)
I'm not angry about it. Sometimes we have people posting who have
difficulty expressing themselves in English. They might make a post, and
then wait a couple of days, before wondering why no one is answering their
question, not realizing that nobody sees a question in the post that they
made.
So I was checking if you had a question or not.
- Oliver
Luc The Perverse - 05 Apr 2007 22:43 GMT
> Hi! :-)
>
[quoted text clipped - 9 lines]
>
> Hope you are not angry about it? :-)
Eh . . . I hope you are not planning on making comp.lang.java.programmer
your notepad. hehe.
Remember this is a discussion forum - if you want to make a collaboration of
notes and hints you can make a website or blogsite for that.
If you do want to post a tip or a hint, please indicate so in the subject
line so it does not appear to be a question for those people who do not want
to read it :)
Take care! See ya!
--
LTP
:)
Lew - 05 Apr 2007 23:21 GMT
> Remember this is a discussion forum - if you want to make a collaboration of
> notes and hints you can make a website or blogsite for that.
How is it that collaborations of notes and hints are not considered discussions?

Signature
Lew
Luc The Perverse - 06 Apr 2007 01:15 GMT
>> Remember this is a discussion forum - if you want to make a collaboration
>> of notes and hints you can make a website or blogsite for that.
>
> How is it that collaborations of notes and hints are not considered
> discussions?
It is my opinion that he should not post closed ended "hints" that out of
context are not particularly useful.
This is only my opinion - if you hadn't snipped my last paragraph you would
see I did not tell him to not post tips.
The problem with "beginners tips" is that beginners are not going to know
what they are missing - and hence will not proactively seek it out.
Posting a solution to a unique or interesting problem doesn't bother me.
Four replies to yourself about all the trials and efforts of concatenating
the strings in an array does not qualify in my book.
I'm not opposed to tips - but it sounded like he wanted to use the NG as
scratch paper which was in line with what I was seeing.
--
LTP
:)
Oliver Wong - 05 Apr 2007 17:29 GMT
> It is amazing that java.lang.String class has a split method but no
> reverse mechanism for joining, like the "join" method some languages
> such as VB/VB.NET and the .NET framework support.
>
> http://java.sun.com/j2se/1.4.2/docs/api/java/lang/String.html#split(java.lang.String)
See java.util.Arrays.toString() and .deepToString()
- Oliver
Tom Hawtin - 05 Apr 2007 17:48 GMT
>> http://java.sun.com/j2se/1.4.2/docs/api/java/lang/String.html#split(java.lang.String)
>
> See java.util.Arrays.toString() and .deepToString()
You get a load of unwanted characters in your string if you do that. I
think you are still left with writing a little concatenation loop.
Tom Hawtin
Lew - 05 Apr 2007 22:46 GMT
> It is amazing that java.lang.String class has a split method but no
> reverse mechanism for joining, like the "join" method some languages
> such as VB/VB.NET and the .NET framework support.
>
> http://java.sun.com/j2se/1.4.2/docs/api/java/lang/String.html#split(java.lang.String)
What in the world are you talking about? Of course it does, and it's way
older than the split() method!
String [] a = some.split( regex );
String join = "";
for ( String s : a )
{
join = join + s;
}

Signature
Lew
Tor Iver Wilhelmsen - 13 Apr 2007 20:59 GMT
På Thu, 05 Apr 2007 23:46:21 +0200, skrev Lew <lew@nospam.lewscanon.com>:
> String join = "";
> for ( String s : a )
> {
> join = join + s;
> }
Oh, evil! Use a StringBuffer or StringBuilder, otherwise you create and
discard a ton of String/StringBuffer objects in the loop.
Lew - 14 Apr 2007 00:44 GMT
> På Thu, 05 Apr 2007 23:46:21 +0200, skrev Lew <lew@nospam.lewscanon.com>:
>
[quoted text clipped - 6 lines]
> Oh, evil! Use a StringBuffer or StringBuilder, otherwise you create and
> discard a ton of String/StringBuffer objects in the loop.
I forget the original context for that, whether it was intentionally Evil or
used to show the use of the '+' operator for Strings.
Yes, very Evil!

Signature
Lew
Lew - 05 Apr 2007 22:42 GMT
>>From v1.5.x onwards, there is a toString() override in
> java.utils.Arrays class that does it.
>
> http://java.sun.com/j2se/1.5.0/docs/api/java/util/Arrays.html#toString(java.lang
.Object[])
That is not an override.

Signature
Lew
Oliver Wong - 05 Apr 2007 16:09 GMT
> /* I am writing this class to see the output of:
>
[quoted text clipped - 22 lines]
> }
> }
Right. Did you have a question or concern, or were you just sharing
the results of your experiment with the group?
- Oliver
Jason Cavett - 05 Apr 2007 16:42 GMT
> /* I am writing this class to see the output of:
>
[quoted text clipped - 25 lines]
>
> - Show quoted text -
For the record, don't use "Ats" as the class name and then comment it
saying, "It means Array to String." Just name the class
ArrayToString. Variable names should mean something.
Alex Hunsley - 06 Apr 2007 18:08 GMT
>> /* I am writing this class to see the output of:
>>
[quoted text clipped - 29 lines]
> saying, "It means Array to String." Just name the class
> ArrayToString. Variable names should mean something.
Or even better, ArrayToStringConverter or ArrayUtilities or something.
It's usually good to have a descriptive noun in a class name (e.g.
SomethingConverter, BlingConnector, AnimalWalker, etc.)
lex