How to use ArrayList's get() method

后端 未结 5 1971
长发绾君心
长发绾君心 2021-01-04 13:27

I\'m new to java (& to OOP too) and I\'m trying to understand about the class ArrayList but I don\'t understand how to use the get(). I tried searching in net, but could

5条回答
  •  小鲜肉
    小鲜肉 (楼主)
    2021-01-04 14:04

    Here is the official documentation of ArrayList.get().

    Anyway it is very simple, for example

    ArrayList list = new ArrayList();
    list.add("1");
    list.add("2");
    list.add("3");
    String str = (String) list.get(0); // here you get "1" in str
    

提交回复
热议问题