This was the reply I was looking for - optimized code on one line!

Many thanks

Andy_D

On 14 Aug, 19:31, "Dean Rush" <[email protected]> wrote:
> Yes,
>     String strRandom = "Some random string"; char f = strRandom.charAt(2);
> will work.
>
> This will work too:
>     char f = "Some random string".charAt(2);
>
> These work because strRandom and "Some random string" are both instances of
> a String object.
>
> Regards,
> Dean Rush
>
>
>
> -----Original Message-----
> From: [email protected]
>
> [mailto:[email protected]] On Behalf Of Andy_D
> Sent: Friday, August 14, 2009 10:58 AM
> To: Free Java Programming Online Training Course By Sang Shin
> Subject: [java programming] javadoc lab 1011 - 2.13 Compile error
>
> As we know the following code generates a compile error:
>
> // The following code will generate a compile error since you are trying to
> // invoke a instance method through a class.   Fix this compile error.
>         char f = String.charAt(2);
>
> My javadoc lookup works fine and I understand that charAt is an instance
> method so not revelant to String. My (rather silly) is question - what is
> the fix? My suggestion would be:
>
> String strRandom = "Some random string"; char f = strRandom.charAt(2);
>
> I know it may seem obvious but this just seems too simple!?!?
>
> Andy_D

--~--~---------~--~----~------------~-------~--~----~
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to 
[email protected]
For more options, visit this group at 
http://groups.google.com/group/javaprogrammingwithpassion?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to