Daily Archives: May 21, 2009

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…