Since you mentioned unit tests, here are 2 unit tests that proves your code does not work (Based on name, age, email, phone header):
@Test public void testFindIndicesThrowsException() { ClassName x = new ClassName(); try { int[] result = x.findIndices("Name", "age", "FieldThatDoesNotExist", "Phone"); fail("expected exception was not thrown!"); } catch (IllegalArgumentException exception) { assertEquals("One or more of input arguments could not be found in the headers.", exception.getMessage()); } } @Test public void testFindIndices() { ClassName x = new ClassName(); int[] result = x.findIndices("Email", "Phone", "Name", "age"); assertEquals(4, result.length); assertEquals(02, result[0]); assertEquals(13, result[1]); assertEquals(20, result[2]); assertEquals(31, result[3]); } Explanation: You are setting a boolean in a loop. This means it could be set to false on one iteration, then set to true on the next.
Instead, you can set the index to the one found, and if it's not found, throw an error:
int k = 0; for (String s : input) { indices[k] = -1; for (int i = 0; i < this.headers.length; i++) { if (s.equalsIgnoreCase(this.headers[i])) { indices[k] = i; } } // If we never found the item if (indices[k] == -1) { throw new IllegalArgumentException( "One or more of input arguments could not be found in the headers."); } k++; }