for loop on an array of strings

note: my if statement: if (newExteriorColor = availableExteriorColors) shouldn’t be used in this scenario therefor its incorrect so just wanted to clarify that i know its wrong

How can I make a for loop on the availableExteriorColors Array so the program will check if the selected color is equal to any String value in the array?

public class Cars {

    String [] availableExteriorColors = {"Black", "White", "Blue", "Red", "Yellow", "Brown"};

    public static String exteriorColor;
    public static String interiorColor;
    public static String carBrand;
    public static String carModel;
    public static String carPlateLetters;
    public static String carPlateNumber;
    public static int yearOfMake;
    //public static ? vinNumber; 

    public Cars(String newExteriorColor,String newInteriorColor,String newCarBrand,String newCarModel,String newCarPlateLetters,String newCarPlateNumber,int newYearOfMake)  
        if (newExteriorColor = availableExteriorColors)
            newExteriorColor = exteriorColors;
        else {
            System.out.println("Selected exterior color not available");
     return; }


for (String color : AvailableExteriorColors) {
    if (color.equals(selectedColor)) return color;

Leave a Reply

Your email address will not be published. Required fields are marked *