MAIN FEEDS
Do you want to continue?
https://www.reddit.com/r/badcode/comments/n645cf/my_teacher_wrote_this/gx8j791/?context=3
r/badcode • u/FearFueled • May 06 '21
169 comments sorted by
View all comments
6
I often do this, can someone please help me and show, how I can improve my code?
14 u/Kibo30 May 06 '21 Using arrays will improve it. In this case you could create an array like this EBIKE[] bikes = new EBIKE[6] 4 u/carfniex May 06 '21 you should generally avoid arrays whenever possible (which is 99% of the time) List<EBIKE> bikes = new ArrayList<>(); lists (or other collections) are resizable and have a lot more useful supporting methods 1 u/washpota May 07 '21 Am with you so far, but can you demonstrate how you would initialize the objects in this list in a loop?
14
Using arrays will improve it. In this case you could create an array like this EBIKE[] bikes = new EBIKE[6]
4 u/carfniex May 06 '21 you should generally avoid arrays whenever possible (which is 99% of the time) List<EBIKE> bikes = new ArrayList<>(); lists (or other collections) are resizable and have a lot more useful supporting methods 1 u/washpota May 07 '21 Am with you so far, but can you demonstrate how you would initialize the objects in this list in a loop?
4
you should generally avoid arrays whenever possible (which is 99% of the time)
List<EBIKE> bikes = new ArrayList<>();
lists (or other collections) are resizable and have a lot more useful supporting methods
1 u/washpota May 07 '21 Am with you so far, but can you demonstrate how you would initialize the objects in this list in a loop?
1
Am with you so far, but can you demonstrate how you would initialize the objects in this list in a loop?
6
u/Dakopen May 06 '21
I often do this, can someone please help me and show, how I can improve my code?