I'm trying to find an integer inside of an int[] array and return true or false depending on whether or not it's present anywhere, however my code, which I've taken from numerous websites.
My array is as follows:
private static final int[] thirtyOneDays = {1, 3, 5, 7, 8, 10, 12};
And I'm searching it like so:
Arrays.asList(thirtyOneDays).contains(month)
Where month is an integer.
When debugging the program all the variables and fields are set correctly as expected, it just always returns false. Does anyone know why this is?
As for month, it originates from a JTextField on my GUI:
new Validate(txtDay.getText(), txtMonth.getText(), txtYear.getText());
Here's the Validate constructor:
public Validate(String day, String month, String year)
{
instance = this;
if(this.isYearValid(year))
{
if(this.isMonthValid(month, year))
{
if(this.isDayValid(day, month, year))
{
isAllValid = true;
}
}
}
}
And here's the very top of isDayValid():
private boolean isDayValid(String dayS, String monthS, String yearS)
{
int year = Integer.parseInt(yearS);
int month = Integer.parseInt(monthS);
int day = Integer.parseInt(dayS);
~~~~~~~ P.S. What's the difference between:
int[] intArray = {1, 2, 3}
int[] intArray = new int{1, 2, 3, 4}
Integer[] intArray = new Integer{1, 2, 3, 4}