英文:
Filling an array of objects with another array returns memory address
问题
private Trip[] trips;
private int[] distanceTraveled = new int[] { 8, 6, 15, 5 };
for (int i = 0; i < distanceTraveled.length; i++) {
trips[i] = new Trip(0, i, distanceTraveled[i]);
}
for (Trip trip: trips) {
System.out.println(trip.toString());
}
我试图将distanceTraveled
数组中的值填充到Trip[]
对象数组中,但是这段代码返回了以下内容。任何帮助将不胜感激。
@20ce73ec
@393679df
@56627197
英文:
private Trip[] trips;
private int[] distanceTraveled = new int[] { 8, 6, 15, 5 };
for (int i = 0; i < distanceTraveled.length; i++) {
trips[i] = new Trip(0, i, distanceTraveled[i]);
}
for (Trip trip: trips) {
System.out.println(trip.toString());
}
I am trying to write the values in distanceTraveled array to fill the array of objects for Trip[], but this code returns. Any help will be appreciated
@20ce73ec
@393679df
@56627197
答案1
得分: 0
Override toString() method in Trip class.
> Refer: https://www.geeksforgeeks.org/overriding-tostring-method-in-java/
英文:
Override toString() method in Trip class.
> Refer: https://www.geeksforgeeks.org/overriding-tostring-method-in-java/
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论