|
Post by Me on Jan 8, 2008 22:50:54 GMT
I am writing the program we have to make for my exam, and I am trying to clear an array, and java is being ... dumb.
The array name is squares. I tried this ...
squares = {"","","","",""};
and it gives me an error. When I defined it, I put ...
public String[] squares = {"","","","",""};
and it loaded fine. The only way it seems to work is if I do this:
squares = new String[5]; squares[0] = ""; squares[1] = ""; squares[2] = ""; squares[3] = ""; squares[4] = "";
Does anyone know a shorter way to do it? I don't get why my other method of doing it won't work.
|
|
chemdude
Full Member
2B || !2B
Posts: 228
|
Post by chemdude on Jan 9, 2008 1:04:04 GMT
Well, since you're using a regular array, and not a collection, the fastest way would probably to just use a for() loop with the squares[x] = "" method you got working.
|
|