Matt Gerrans
Posts: 1153
Nickname: matt
Registered: Feb, 2002
|
|
Re: Need help with broken caps lock key!
|
Posted: Jul 9, 2002 1:35 PM
|
|
This is silly code, but the idea is that the content of the existing objects in the array are changed, rather than changing what objects are in the array.
import java.util.StringTokenizer;
import java.lang.StringBuffer;
public class SwizzleStick
{
public static void main(String [] args)
{
StringTokenizer st = new StringTokenizer("CHANGE DATA IN INSTANTIATED OBJECTS USING ARRAY");
StringBuffer [] tooManyCaps = new StringBuffer[st.countTokens()];
for( int n = 0; st.hasMoreTokens(); n++ )
tooManyCaps[n] = new StringBuffer( st.nextToken() );
// Now the array is all loaded, let's modify it:
for( int n = 0; n < tooManyCaps.length; n++ )
tooManyCaps[n].replace(0,tooManyCaps[n].length(), tooManyCaps[n].toString().toLowerCase() );
// Now check the results of this silliness:
for( int n = 0; n < tooManyCaps.length; n++ )
System.out.println( "StringBuffer " + (n+1) + ": \"" + tooManyCaps[n] + "\"");
}
}
|
|