标题包含标题项,而composer是每个相应标题的行详细信息。如何动态地向这些对象添加数据。
String [] titles = {" Renaissance"," Baroque"," Classical"," Romantic"};
Composer[][] composerss = {
{
new Composer("Thomas Tallis", "1510-1585"),
new Composer("Josquin Des Prez", "1440-1521"),
new Composer("Pierre de La Rue", "1460-1518"),
},
{
new Composer("Johann Sebastian Bach", "1685-1750"),
new Composer("George Frideric Handel", "1685-1759"),
new Composer("Antonio Vivaldi", "1678-1741"),
new Composer("George Philipp Telemann", "1681-1767"),
},
{
new Composer("Franz Joseph Haydn", "1732-1809"),
new Composer("Wolfgang Amadeus Mozart", "1756-1791"),
new Composer("Barbara of Portugal", "1711Ð1758"),
new Composer("Frederick the Great", "1712Ð1786"),
new Composer("John Stanley", "1712Ð1786"),
new Composer("Luise Adelgunda Gottsched", "1713Ð1762"),
new Composer("Johann Ludwig Krebs", "1713Ð1780"),
new Composer("Carl Philipp Emanuel Bach", "1714Ð1788"),
new Composer("Christoph Willibald Gluck", "1714Ð1787"),
new Composer("Gottfried August Homilius", "1714Ð1785"),
},
{
new Composer("Ludwig van Beethoven", "1770-1827"),
new Composer("Fernando Sor", "1778-1839"),
new Composer("Johann Strauss I", "1804-1849"),
},
};
答案 0 :(得分:3)
您无法在不重建/重新创建数组的情况下将项添加到数组中 - 这就是ArrayList所做的事情:它在内部保存数组,当您添加项时,ArrayList会使用添加的项重新创建数组。
换句话说 - 您应该检查ArrayList是否可以作为您的答案。