java - How to get the last three value of Arraylist -
hi how can last 3 values of list.i tried this
stringary.get(stringary.size()-1);
but displays last item of list. how can last 3 values of list. pls guide me. possible store 3 values in string array
if (stringary.size() >= 3) // make sure have 3 elements { list<string> array = new arraylist<string>(); array.add(stringary.get(stringary.size()-1)); // last array.add(stringary.get(stringary.size()-2)); // 1 before last array.add(stringary.get(stringary.size()-3)); // 1 before 1 before last system.out.println(array); }
Comments
Post a Comment