Re: check values of Boolean array
On May 21, 4:04 pm, "printdude1...@gmail.com"
<printdude1...@gmail.com> wrote:
Here's a program that works. It checks each element of an array to
see if it's a boolean. The first non-boolean it encounters returns a
false
/*
* CheckBoolean.java
*
* Created on May 22, 2007, 6:06 PM
*
* To change this template, choose Tools | Template Manager
* and open the template in the editor.
*/
package help.java.lang.comp;
/**
*
* @author John
*/
public class CheckBoolean {
public static void main(String [] args) {
Object[] array = new Object[5];
String xxx = "Hello";
Integer yyy = 1;
array[0] = yyy;
array[1] = true;
array[2] = xxx;
array[3] = false;
array[4] = true;
boolean result = checkArray(array);
System.out.println(result);
}
public static boolean checkArray(Object [] ArrayToCheck) {
int i = 0;
while (i < ArrayToCheck.length) {
Object test = ArrayToCheck[i];
if( ! (test instanceof java.lang.Boolean))
return false;
i++;
}
return true;
}
}
init:
deps-jar:
Compiling 1 source file to Z:\javaProjects\StuffFromTheWeb\build
\classes
compile-single:
run-single:
false
BUILD SUCCESSFUL (total time: 0 seconds)