Results 1 to 4 of 4
  1. #1
    maas is offline Member
    Join Date
    Jul 2010
    Posts
    37
    Rep Power
    0

    Default How to add variables and default values to arraylist

    Hello

    I am facing difficulties in identifying the proper way to add the selected colors of cards into an arraylist. I am having an arraylist which is:

    Java Code:
    private List<String> selectedCars = new ArrayList<String>();
    And one more for the carColors:

    Java Code:
    private List<String> carColors = new ArrayList<String>();
    Th selectedCards array will store the selected cars ['TOYOTA','MAZDA','NISSAN'] as per the selection from the user.For certain types, there is one default color which is 'Black', however for some of them, the user can select different colors.(ex. if selection is 'Toyota')
    Java Code:
    String carColor="";
    String toyotaColor=""; // The value will be retrieved from the form once the user selected the color
    
    if (selectedCars.contains("MAZDA"))
    {
    carColor="Black";
    }
    else if (selectedCars.contains("TOYOTA"))
    {
    carColor=toyotaColor;
    }
    else if (selectedCars.contains("NISSAN"))
    {
    carColor="Black";
    }
    else if (selectedCars.contains("FORD"))
    {
    carColor="Black";
    }
    Now the issue is that I want to pass the selected colors in a string array for the selected cars to a procedure separated by ' , ' so how can I do this. I need to store the carColors in an arraylist based on the selectedCards as the selected cars are : ['TOYOTA','MAZDA','NISSAN'] and I want to do the coding for an arraylist for the carColors which is equivalent to selectedCars which will be [toyotaColor,'Black','Black']

    The code for calling the procedure is:
    Java Code:
    CallableStatement callableStatement =
        connection.prepareCall("{call processCarSelection(?, ?)}");
    
    callableStatement.setString(1, carModel);
    callableStatement.setString   (2, ); //What should I pass here?
    Thanks

  2. #2
    jim829 is offline Senior Member
    Join Date
    Jan 2013
    Location
    Northern Virginia, United States
    Posts
    6,226
    Rep Power
    15

    Default Re: How to add variables and default values to arraylist

    I am not certain what you are asking. Can you be more specific? Do you really want a String array of carColors or a csv String of carColors?

    Regards,
    Jim
    The JavaTM Tutorials | SSCCE | Java Naming Conventions
    Poor planning on your part does not constitute an emergency on my part

  3. #3
    maas is offline Member
    Join Date
    Jul 2010
    Posts
    37
    Rep Power
    0

    Default Re: How to add variables and default values to arraylist

    Thanks JIM for your response.

    I want a string array.

    My problem is that I want to pass the selected colors in a string array for each selected car in the selectedCars arraylist. In addition, I would like the separation between the colors should be ' ,' comma. so how can I do this?

    In details, I need to store the carColors values in an arraylist for each item in the selectedCars array as an example the selected cars are : ['TOYOTA','MAZDA','NISSAN'] and I want to do the coding for an arraylist for the carColors which should be [toyotaColor,'Black','Black']

  4. #4
    jim829 is offline Senior Member
    Join Date
    Jan 2013
    Location
    Northern Virginia, United States
    Posts
    6,226
    Rep Power
    15

    Default Re: How to add variables and default values to arraylist

    Ok, I do not clearly understand. If you want an array like the following:

    Java Code:
    String[] colors = new String[3];
    colors[0] = "Red";
    colors[1] ="Yellow";
    colors[2] = "Blue";
    Then why do you want the commas? I could understand the need for them if you wanted this:
    Java Code:
    String colors = "Red,Yellow,Blue";
    Regards,
    Jim
    The JavaTM Tutorials | SSCCE | Java Naming Conventions
    Poor planning on your part does not constitute an emergency on my part

Similar Threads

  1. How to display default constructor values?
    By IanKW in forum New To Java
    Replies: 3
    Last Post: 09-14-2014, 11:25 AM
  2. Default values of stored procedures
    By vinayakshukre in forum JDBC
    Replies: 2
    Last Post: 01-13-2009, 01:05 PM
  3. Printing default Swing values
    By Java Tip in forum Java Tip
    Replies: 0
    Last Post: 03-12-2008, 12:09 PM

Posting Permissions

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