This code works great for preparing the dynamic values Array for spinner in Android:
List<String> yearStringList = new ArrayList<>();
yearStringList.add("2017");
yearStringList.add("2018");
yearStringList.add("2019");
String[] yearStringArray = (String[]) yearStringList.toArray(new String[yearStringList.size()]);