ALSTRA ALSTRA - 5 months ago 8
Java Question

Why can't I initialize this List<List<String>>?

Why isn't this possible to do?

private ObservableList<List<String>> fnlData;
.
.
fnlData.get(i).get(indexC) = null;


It says:

this happens

Answer

fnlData.get(i).get(indexC) is the value of a method call. You can't assign anything to the value of a method call.

You can initialize elements of your Lists with set :

fnlData.get(i).set(indexC,null);

Of course, fnlData.get(i) must be initialized first. And set(indexC,null) will only work if the List returned by fnlData.get(i) already contains at least indexC+1 elements.

Comments