Let's say have an ArrayList inside another ArrayList whitch contains Strings.
private List<ArrayList<String>> strings = new ArrayList<ArrayList<String>>();
After adding some arrays and strings i want to get the last string in the last array, how do I do?
Well, you can use:
ArrayList<String> lastList = strings.get(strings.size() - 1);
String lastString = lastList.get(lastList.size() - 1);
Or with Guava (or your own getLast
method, which would be easy to write...):
String lastString = Iterables.last(Iterables.last(strings));
List<String> lastInnerList = strings.get(strings.size() - 1);
String lastString = lastInnerList.get(lastInnerList.size() - 1);
String lastElement = strings.get(strings.size()-1).get(strings.get(strings.size()-1).size()-1);
int outerListSize = strings.size();
ArrayList<String> lastInnerList = strings.get(outerListSize - 1);
int lastInnerListSize = lastInnerList.size();
String str = lastInnerList.get(lastInnerListSize - 1);
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.