“Exception in thread ”main“ java.lang.IndexOutOfBoundsException: Index: 0, Size: 0” with ArrayList?

前端 未结 4 1283
长情又很酷
长情又很酷 2020-12-11 23:12

\"Exception in thread \"main\" java.lang.IndexOutOfBoundsException: Index: 0, Size: 0\" is the main error I get when I compile this method:

public static Arr         


        
4条回答
  •  悲&欢浪女
    2020-12-12 00:06

    Do not use list.set(index, element) on a nonexistent element, since it replaces the old (nonexistent) element with a new one and returns the old one. Instead, use list.add(index, element) and it will work.

提交回复
热议问题