The Artima Developer Community
Sponsored Link

Java Answers Forum
Need help: ARRAYS CHANGE DATA IN INSTANTIATED OBJECTS

1 reply on 1 page. Most recent reply: Jul 9, 2002 1:35 PM by Matt Gerrans

Welcome Guest
  Sign In

Go back to the topic listing  Back to Topic List Click to reply to this topic  Reply to this Topic Click to search messages in this forum  Search Forum Click for a threaded view of the topic  Threaded View   
Previous Topic   Next Topic
Flat View: This topic has 1 reply on 1 page
chuck

Posts: 9
Nickname: chuckjava2
Registered: Jul, 2002

Need help: ARRAYS CHANGE DATA IN INSTANTIATED OBJECTS Posted: Jul 9, 2002 1:06 PM
Reply to this message Reply
Advertisement
Please give me an small example how to CHANGE DATA IN INSTANTIATED OBJECTS USING ARRAY. Thank you very much.


Matt Gerrans

Posts: 1153
Nickname: matt
Registered: Feb, 2002

Re: Need help with broken caps lock key! Posted: Jul 9, 2002 1:35 PM
Reply to this message Reply
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] + "\"");
   }
}

Flat View: This topic has 1 reply on 1 page
Topic: using JSplitPane with JScrollPAne Previous Topic   Next Topic Topic: JavaScript popup screen

Sponsored Links



Google
  Web Artima.com   

Copyright © 1996-2019 Artima, Inc. All Rights Reserved. - Privacy Policy - Terms of Use