Article View: borland.public.jbuilder.java.language
Article #18636Re: Printing Arrays!! No. 2
From: Ken Chan
Date: Mon, 11 May 1998 00:00
Date: Mon, 11 May 1998 00:00
27 lines
1386 bytes
1386 bytes
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:
<MPG.fc150a094c11db898993c@forums.borland.com>Path:
arc1-ca.pugleaf.net!unknown!not-for-mailReferences:
<6itei3$u01@forums.borland.com> <6iuar5$u014@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: supportinfo@borland.com (Ken Chan) Subject: Re: Printing Arrays!! No. 2 Date: 1998/05/11 Message-ID: <MPG.fc150a094c11db898993c@forums.borland.com> X-Deja-AN: 352400025 References: <6itei3$u01@forums.borland.com> <6iuar5$u014@forums.borland.com> Organization: Borland Newsgroups: borland.public.jbuilder.java.language