Jesse Jesse - 1 year ago 62
Java Question

How to check the first index of an arraylist if it equals to a value?


How to check if a arraylist's first value is equal to some value?
In my attempt I am trying to search in "Status" to see if it contains the values.

List<Employees> data = new Arraylist<Employees>();
data.add(new Employees (Status, FirstName, LastName, age));


if (data.contains("Inactive")) {
System.out.println("There are inactive Employees");
else if (data.contains("{Parttime")) {
System.out.println("There are part time Employees");
else {
System.out.println("All are full time Employees");

Currently I am receiving "All are full time Employees". I am not worried about the count. If there is one inactive employee then I should be notified.

I receive the output: [;@28a418. Would this cause the fault?

Answer Source

As I understand, you have a List<Employee> data; and Employee object contain string field - status. Try this:

String status = data.get(0).getStatus();
if (status != null && status.contains("Inactive")) {
    System.out.println("There are inactive Employees");
    } .....
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download