Premium Content - Free Preview
Previously, you saw that an ArrayList could be created with a simple line of code:
ArrayList someList = new ArrayList();
This works to create an ArrayList, but there's one issue: it doesn't state what Class of Objects it will hold. In most cases you'll want an ArrayList that only holds Objects of one Class, so your program will know what it's getting when it accesses an element in it. To specify the Objects that an ArrayList will hold, you use the Angle Brackets syntax. For example: *
ArrayList<String> someList = new ArrayList<String>();
This code will create an ArrayList of String, which will only hold String Objects.