arraylists' an array is a variable type that represents a list of items. you access individual...
Post on 22-May-2020
11 Views
Preview:
TRANSCRIPT
• Avariabletypethatrepresentsalistofitems.
• Youaccessindividualitemsbyindex.
• Storeasingletypeofobject(String,GRect,etc.)
• Resizable – canaddandremoveelements
• Hashelpfulmethodsforsearchingforitems
Meet ArrayLists
Wow! Nice to meet you!
//Createan(initiallyempty)listArrayList <Integer>list=new ArrayList<Integer>();
//Addanelementtothebacklist.add(16);//nowsize1list.add(42);//nowsize2
ArrayList
//Createan(initiallyempty)listArrayList <Integer>list=new ArrayList<Integer>();
//Addanelementtothebacklist.add(16);//nowsize1list.add(42);//nowsize2
//Accesselementsbyindex(startingat0!)println(list.get(0));//prints16println(list.get(1));//prints42
ArrayList
//Accesselementsbyindex(startingat0!)for(int i =0;i <list.size();i++){println(list.get(i));
}
ArrayList
top related