Article View: borland.public.jbuilder.java.language
Article #18638Re: Printing Arrays!! No. 2
From: Howard Weiner
Date: Tue, 12 May 1998 00:00
Date: Tue, 12 May 1998 00:00
35 lines
1768 bytes
1768 bytes
Sorry folks, but according to the Java spec, it should work.
Both the PrintStream and PrintWriter classes feature a print/println method
which accepts both a single character and a character array.
HDW
Ken Chan wrote in message ...
>Rob C wrote:
>> String roc = "Rocker"
>>
>> should read
>>
>> char roc[] = {'R', 'o', 'c', 'k', 'e', 'r'};
>
>Actually, it probably shouldn't <g>. Unlike C, in Java a String is not an
>array of characters. Therefore, you can't call roc.substring(), because
>the array roc does not have a substring() method. (About all you can do
>with an array is gets its .length and access its elements.)
>
>The error you got is probably due to the compiler attempting to check the
>base classes for the named method, all the way back to plain old Object.
>
>It is perfectly legal to define an array of characters. But to print it,
>you will have to loop through the array, or copy them into a string with:
>
> new String( char[], int offset, int count )
>
>which seems like cheating <g>, or any other number of ways; just not the
>way you were trying....
>
>--
>//Ken@Inprise
><Please follow-up to newsgroup; do not reply to email>
>
Technical Details
Message-ID:
<6j9fbq$9vs14@forums.borland.com>Path:
arc1-ca.pugleaf.net!unknown!not-for-mailReferences:
<6itei3$u01@forums.borland.com> <6iuar5$u014@forums.borland.com> <MPG.fc150a094c11db898993c@forums.borland.com>Show Full Headers
Complete Article Headers
X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: f74b3,4c54a2bc3cc4521f X-Google-Attributes: gidf74b3,public From: "Howard Weiner" <HDWeiner@erols.com> Subject: Re: Printing Arrays!! No. 2 Date: 1998/05/12 Message-ID: <6j9fbq$9vs14@forums.borland.com> X-Deja-AN: 352530213 References: <6itei3$u01@forums.borland.com> <6iuar5$u014@forums.borland.com> <MPG.fc150a094c11db898993c@forums.borland.com> X-MimeOLE: Produced By Microsoft MimeOLE V4.72.2106.4 Organization: Another Netscape Collabra Server User Newsgroups: borland.public.jbuilder.java.language