I want to write a variable only if it is already gone. Here is my code so far.
if (inv[0] == null) { inv[0]=map.getTileId(tileX-1, tileY-1, 0); }
This gives me this error:
java.lang.Error: Unresolved compilation problem: The operator == is undefined for the argument type(s) int, null
I guess that invis int[].
inv
int[]
There is no such thing as an existing value or not in an array. For instance:
int[] x = new int[5];
has exactly the same content as:
int[] x = new int[5]; x[3] = 0;
Now, if you used Integer[], you could use a null value to indicate "unvisited" ... is that what you want?
Integer[]
, - null , Integer.
null
Integer
inv int[], int null, , .int java.
int
, inv int[]. int null, null , . - (0 , , ) inv a Integer[] (Integer , null -able).
0
, inv[] int, int java , null. 0 ( int).
inv[]
Java .
... int - . .
:
int [] arr = new int [10]; System.out.println(arr.size());
0 - 1, . , int null, - , ArrayOutOfBoundsException.
ArrayOutOfBoundsException
" ", PHP JavaScript, Map:
Map
Map<Integer, Integer> map = new HashMap(); map.put( 1, 324 ); if( map.get( 2 ) == null ) ...
-
Integer[] inv = new Integer[10]; inv[0] = 1; inv[1] = 2; .... if(inv[3] == null) { inv[3] = getSomeValue(); }
, inv - int, Integer. , .
int[] inv = new int[5];
5 .
, , , , (, , ). .
.
You can check if there is an if> 0 number to see if the value exists:
if(inv[0] <= 0) { inv[0]=map.getTileId(tileX-1, tileY-1, 0); }