tomcat-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Matt Egyhazy <mw...@virginia.edu>
Subject Re: Vectors? Why does this not work?
Date Thu, 10 Jan 2002 21:04:39 GMT
it looks like your code is working just fine to me, its doing exactly what
you wrote it to do.  i suggest reading an introductory java book, the wrox
java2 book is ok.  and this is not the mailing list for these types of
questions.

matt
----- Original Message -----
From: "Rick Roberts" <techinfo@ait-web.com>
To: "Tomcat Users List" <tomcat-user@jakarta.apache.org>
Sent: Thursday, January 10, 2002 3:49 PM
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