I am still new to Java.
I am wondering if there is a quick way to initialize a Java Array with size (n*1
or n*m
) and values (0.0, or 1, or "A"
)provided.
In this post, Initialization of an ArrayList in one line, intilizing Java array is given as follows:
ArrayList<String> list = new ArrayList<String>();
list.add("A");
list.add("B");
list.add("C");
or
List<String> list = ["A", "B", "C"];
or
List<String> list = List.of("A", "B", "C");
However, none of them is what I want.
I am wondering if it is possible to initialize an Java array of size n*1
or n*m
with 0.0
(double array), or 1
(integer array), or "A"
(string array).
These initialization will be one/two line code in matlab/python, e.g. In python, ZerosVector = numpy.zeros((n,1))
will return a n*1
vector with zeros. In matlab CellMatrix = cell(10,20); CellMatrix(:) ="A"
will return a cell matrix with string "A".
Any equivalent package/implementation in Java for such fast initialization without using loop?