I am trying to return a list of integers having length of the list/array passed.
But it's returning null pointer exception error. Should I use any other data structure for the same List, array etc.
What would be the best to be used.
import java.util.ArrayList;
public class App {
private static ArrayList<Integer> a;
public static ArrayList<Integer> map(String[] x) {
for (int i = 0; i < x.length; i++) {
a.add(x[i].length());
}
return a;
}
public static void main(String[] args) {
String[] string = { "hello", "how", "r", "you" };
System.out.println(map(string).toString());
}
}