Converting a subList of an ArrayList to an ArrayList

后端 未结 2 1209
遇见更好的自我
遇见更好的自我 2021-02-01 13:42

Im using an ArrayList and im trying to copy a part of it to another ArrayList therefore im using:

sibling.keys = (ArrayList) keys.subList(mid, thi         


        
2条回答
  •  别跟我提以往
    2021-02-01 14:28

    You get the class cast exception because you are expecting an ArraList while the ArrayList.subList()does not return ArrayList. Change your sibling.keys from ArrayList to List, and should work fine. This will avoid ClassCastException as well as you will not need to and any cast.

提交回复
热议问题