A fo’ real Ah Ha! Moment!! learning Java


Ah ha!!!!

Couldn’t get .replace(), .replaceAll() or .split() to work:

String s = new String(“electric foo bar);

s.replace( ‘e’, ‘E’ ); // char, replace every one, WOULDN’T compile

s.replaceAll( “e”, “E” ); // String – this WOULD compile, did nothing
s.replaceAll( “e”, ” -Eek!- ” );
// ditto
s.replaceAll( ” -Eek!- “, “e” );
// ditto

what was needed was:

s = s.replace( ‘e’, ‘E’ ); // MUST Assign the return string.

The compiler probably took returnAll() because it returns a reference to an array of array references… ok, sure, implict cast to VOID. Next.

Consistancy? We ain’t got no stinkin’ consistancy!

How very human this Java stuff is…

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s