Prior to java 15 if you needed a list of strings there were


Question: Prior to Java 1.5, if you needed a list of Strings, there were at least two approaches you could take. The first approach was to create an object, such as an Array List, that implemented the List interface and then populate it with Strings. However, whenever you fetched a String from the list, you needed to typecast the object returned by the list since the Array List's get method had a return type of Object. Furthermore, it was hard to ensure that no one accidentally added a non-String object to the list. Therefore, an alternative approach was to use the Adapter pattern and create a new String List class that behaved just like a List except that its add methods took a String as its parameter and its get method had a return type of String. To store the Strings, the String List class would reference an Array List or other List object. With the arrival of Java 1.5, a third, easier approach is possible. Explain that third approach.

Request for Solution File

Ask an Expert for Answer!!
Basic Computer Science: Prior to java 15 if you needed a list of strings there were
Reference No:- TGS02580304

Expected delivery within 24 Hours