tomcat-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Randy Layman <randy.lay...@aswethink.com>
Subject RE: Vectors? Why does this not work?
Date Thu, 10 Jan 2002 20:08:28 GMT

	First, you should take this question to another forum since this one
is about the Tomcat Servlet Container.

	Second, you probably need to do some basic Java learning since this.

	Third, you are using static variables to hold your names.

	Randy


> -----Original Message-----
> From: Rick Roberts [mailto:techinfo@ait-web.com]
> Sent: Thursday, January 10, 2002 3:50 PM
> To: Tomcat Users List
> Subject: Vectors? Why does this not work?
> 
> 
> Why does this simple example not work?
> I am using Tomcat 3.3 and JDK 1.3.1_01 and Redhat Linux 7.2
> 
> Thanks,
> 
> ==============
> 
> // SimpleClass.java
> // A Simple Class
> public class SimpleClass extends Object{
>     private static String last_name;
>     private static String first_name;
>     private static String middle_name;
> 
>     // Constructor
>     public SimpleClass() {
>         this.last_name = null;
>         this.first_name = null;
>         this.middle_name = null;
>     }
> 
>     public void setLastName( String val ) {
>         this.last_name = val;
>     }
> 
>     public String getLastName( ) {
>         return this.last_name;
>     }
> 
>     public void setFirstName( String val ) {
>         this.first_name = val;
>     }
> 
>     public String getFirstName( ) {
>         return this.first_name;
>     }
> 
>     public void setMiddleName( String val ) {
>         this.middle_name = val;
>     }
> 
>     public String getMiddleName( ) {
>         return this.middle_name;
>     }
> 
>     public String getFullName( ) {
>         return this.last_name + (this.first_name == null ? "" 
> : ", " + 
> this.first_name) + (this.middle_name == null ? "" : " " + 
> this.middle_name);
>     }
> 
> }// class SimpleClass
> ============
> 
> 
> // VectorTest.java
> // A Simple Vector Test
> import java.util.*;
> 
> import SimpleClass;
> 
> class VectorTest{
> 
>     public static void main( String args[] ){
>         Vector v = new Vector();
> 
>         String firstNames[] = {
>             "George",
>             "John",
>             "Thomas",
>             "James",
>             "James",
>             "John",
>             "Andrew",
>             "Martin",
>             "William",
>             "John",
>             "James",
>             "Zachary",
>             "Millard",
>             "Franklin",
>             "James"
>         };
> 
>         String lastNames[] = {
>             "Washington",
>             "Adams",
>             "Jefferson",
>             "Madison",
>             "Monroe",
>             "Adams",
>             "Jackson",
>             "Buren",
>             "Harrison",
>             "Tyler",
>             "Polk",
>             "Taylor",
>             "Filmore",
>             "Pierce",
>             "Buchanan"
>         };
> 
>         System.out.println( "\nPut class in Vector." );
>         for( int i=0; i<15; i++ ){
>             SimpleClass inClass = new SimpleClass();
>             inClass.setFirstName( firstNames[i] );
>             inClass.setLastName( lastNames[i] );
>             System.out.println( i + ": " + inClass.getFullName() );
>             v.addElement( inClass );
>         }
> 
>         System.out.println( "\n\nRetrieve class from Vector." );
>         for( int i=0; i<15; i++ ){
>             SimpleClass outClass = (SimpleClass)v.elementAt( i );
>             System.out.println( i + ": " + outClass.getFullName() );
>         }
> 
>     } //main()
> 
> }//class VectorTest
> =============
> 
> Here is my output:
> 
> [projects]# java VectorTest
> 
> Put class in Vector.
> 0: Washington, George
> 1: Adams, John
> 2: Jefferson, Thomas
> 3: Madison, James
> 4: Monroe, James
> 5: Adams, John
> 6: Jackson, Andrew
> 7: Buren, Martin
> 8: Harrison, William
> 9: Tyler, John
> 10: Polk, James
> 11: Taylor, Zachary
> 12: Filmore, Millard
> 13: Pierce, Franklin
> 14: Buchanan, James
> 
> 
> Retrieve class from Vector.
> 0: Buchanan, James
> 1: Buchanan, James
> 2: Buchanan, James
> 3: Buchanan, James
> 4: Buchanan, James
> 5: Buchanan, James
> 6: Buchanan, James
> 7: Buchanan, James
> 8: Buchanan, James
> 9: Buchanan, James
> 10: Buchanan, James
> 11: Buchanan, James
> 12: Buchanan, James
> 13: Buchanan, James
> 14: Buchanan, James
> 
> -- 
> *******************************************
> * Rick Roberts                            *
> * Advanced Information Technologies, Inc. *
> *******************************************
> 
> 
> 
> --
> To unsubscribe:   <mailto:tomcat-user-unsubscribe@jakarta.apache.org>
> For additional commands: <mailto:tomcat-user-help@jakarta.apache.org>
> Troubles with the list: <mailto:tomcat-user-owner@jakarta.apache.org>
> 

--
To unsubscribe:   <mailto:tomcat-user-unsubscribe@jakarta.apache.org>
For additional commands: <mailto:tomcat-user-help@jakarta.apache.org>
Troubles with the list: <mailto:tomcat-user-owner@jakarta.apache.org>


Mime
View raw message