Adding data to an array. Im a beginner, help me out!!1:D

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • carlos123
    New Member
    • Sep 2007
    • 53

    #1

    Adding data to an array. Im a beginner, help me out!!1:D

    Ok i just want to thank you for checking this out and helping me out. This is the problem, well not really problem, but this is what i want to do.

    I have a bunch of textfields, when the "save" button is pressed, all the information is added to a database which is a bunch of arrays. This is all i have on that.
    Code:
     if (event.getSource() == Bok)
               {
               
                firststring = first.getText();
                laststring = last.getText();
                 agestring = age.getText();
                streetstring = street.getText();
                citystring = city.getText();
                
               }
    I want this information to go into these arrays.

    Code:
    String[] firsta = new String[30];
           String[] lasta = new String[30];
           String[] agea = new String[30] ;
           String[] citya = new String[30];
           String[] streeta = new String[30] ;
    Would someone explain how that would be done, please include some code. Please dont just write what should happen, because i wont be able to put it together. Im not asking you to do my homework, but i just need a place to start. This is only the beginning of this program, and im already lost. It might be easier to use arraylists??? Im uncertain how to use those exactly. Thanks for your time.
  • dmjpro
    Top Contributor
    • Jan 2007
    • 2476

    #2
    Originally posted by carlos123
    Ok i just want to thank you for checking this out and helping me out. This is the problem, well not really problem, but this is what i want to do.

    I have a bunch of textfields, when the "save" button is pressed, all the information is added to a database which is a bunch of arrays. This is all i have on that.
    Code:
     if (event.getSource() == Bok)
               {
               
                firststring = first.getText();
                laststring = last.getText();
                 agestring = age.getText();
                streetstring = street.getText();
                citystring = city.getText();
                
               }
    I want this information to go into these arrays.

    Code:
    String[] firsta = new String[30];
           String[] lasta = new String[30];
           String[] agea = new String[30] ;
           String[] citya = new String[30];
           String[] streeta = new String[30] ;
    Would someone explain how that would be done, please include some code. Please dont just write what should happen, because i wont be able to put it together. Im not asking you to do my homework, but i just need a place to start. This is only the beginning of this program, and im already lost. It might be easier to use arraylists??? Im uncertain how to use those exactly. Thanks for your time.
    [code=java]
    String arr = new arr[2];
    arr[0]="some_value ";
    arr[1]="some_value ";
    [/code]

    Kind regards,
    Dmjpro.

    Comment

    • r035198x
      MVP
      • Sep 2006
      • 13225

      #3
      Originally posted by carlos123
      Ok i just want to thank you for checking this out and helping me out. This is the problem, well not really problem, but this is what i want to do.

      I have a bunch of textfields, when the "save" button is pressed, all the information is added to a database which is a bunch of arrays. This is all i have on that.
      Code:
       if (event.getSource() == Bok)
                 {
                 
                  firststring = first.getText();
                  laststring = last.getText();
                   agestring = age.getText();
                  streetstring = street.getText();
                  citystring = city.getText();
                  
                 }
      I want this information to go into these arrays.

      Code:
      String[] firsta = new String[30];
             String[] lasta = new String[30];
             String[] agea = new String[30] ;
             String[] citya = new String[30];
             String[] streeta = new String[30] ;
      Would someone explain how that would be done, please include some code. Please dont just write what should happen, because i wont be able to put it together. Im not asking you to do my homework, but i just need a place to start. This is only the beginning of this program, and im already lost. It might be easier to use arraylists??? Im uncertain how to use those exactly. Thanks for your time.
      If you want to learn Java here you better start taking the advice that's given to you. In your last problem you were taught about how arrays are so Fortranesque yet you keep using them.

      Comment

      • JosAH
        Recognized Expert MVP
        • Mar 2007
        • 11453

        #4
        IMHO there should be a 'Person' class with 'firstName', 'lastName', 'age' etc. members
        and all the getXXX methods; setXXX methods are probably not necessary for all
        members. I'd implement an 'equals()' and 'hashCode()' method for that class as
        well so that it can safely be stored in a Set<Person> set that mimics a database.
        Probably a 'toString()' method comes in handy as well.

        Last but not least: I'd avoid arrays like the plague for purposes like these.

        kind regards,

        Jos

        Comment

        • carlos123
          New Member
          • Sep 2007
          • 53

          #5
          Im sorry, i dont really understand. Could i see some sample code on how that would work? Also, the save button, has to clear the textfields. Would there be an easier way of inputing the data?

          Comment

          • carlos123
            New Member
            • Sep 2007
            • 53

            #6
            Code:
             if (event.getSource() == save)
                       {
                      while (i < 30; i++} //why doesnt this work?
                       {
                        firsta[i] = first.getText();
                        lasta[i] = last.getText();
                        agesa[i] = age.getText();
                        streeta[i] = street.getText();
                        citya[i] = city.getText();
                    }
                       }

            Comment

            • r035198x
              MVP
              • Sep 2006
              • 13225

              #7
              Please don't keep starting multiple threads for the same problem.
              It is against site rules and is therefore a punishable offence.

              Comment

              Working...