Results 1 to 2 of 2

Thread: Multidimensional Array?

  1. #1

    Thread Starter
    Hyperactive Member rockies1's Avatar
    Join Date
    Jul 1999
    Location
    Stuck at work
    Posts
    375

    Multidimensional Array?

    How do I use a multidimensional array?

    I will have an unknown number of records with 10 fields apiece.

    Is an array the way to go or is there a better way?

    Thanks!
    Morgan
    [email protected] - Home
    [email protected] - Work
    Using VB6 SP6 but trying to learn VB2005EE

  2. #2
    Dazed Member
    Join Date
    Oct 1999
    Location
    Ridgefield Park, NJ
    Posts
    3,418
    I would think that an array would be enough rather than use a multidimensional array.
    Code:
    public class Y{
      public static void main(String[] args){
       X x = new X();
       x.findRecord("Bill Murray");  
     } 
    }
     class X{
      private Employee[] emp;
    
     public X(){
      emp = new Employee[] {new Employee(165,"Craig Johnson"), new Employee(182,"Bill Murray")}; 
     }
      public void findRecord(String persontofind){
        for(int i = 0; i < emp.length; ++i){
         if(emp[i].getEmpName().equals(persontofind)){
          System.out.print(emp[i].getEmpId() + "\t");
           System.out.print(emp[i].getEmpName());
            break; 
      }else{
           if(i == emp.length - 1){
            System.out.println("Employee could not be found"); 
           }
          } 
         }
        }
       } 
    
     class Employee{
      private int empid; 
      private String name; 
       
      public Employee(int empid, String name){
        this.empid = empid; 
        this.name  = name; 
      }
      
      public int getEmpId(){return empid;} 
      public String getEmpName(){return name;}
     }

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width