1

How to substring String from ArrayList?

view story
linux-howto

http://stackoverflow.com – I have one problem with java.lang.StringIndexOutOfBoundsException: length=3; index=-2 I have this code private static ArrayList<String> array = new ArrayList<String>(); for(int i=0; i<array.size(); i++) { String colorPom = array.get(i).toString().substring(array.get(i).toString().length() -5); } And the problem is that all strings in my array have more than 5 characters and I need to get last 5 characters of each string. But I always got this error: java.lang.StringIndexOutOfBoundsException: length=3; index=-2 that length is only 3, but as I said all strings hav (HowTos)