As revealed in a comment, the actual problem is that you had not given enough information in your question.
In Java, Integers are objects, whereas ints are also integers, yet they are primitive data types instead. An int maps more or less directly to a simple set of bits that are manipulated via arithmetic operations. I will not go into depth here about the differences, but the key is that Integer != int.
The proper code would look more like the following:
ArrayList<Integer> whitespaces_array = new ArrayList<Integer>();
for ( int i = 0; i < length; ++i ) {
if ( word.charAt( i ) == ' ' ) {
whitespaces_array.add( i );
}
}
if (word.charAt(i) == ' ') { ...whitespaces_arraydefined as?