Itsumo Snow wrote:why when I write : newArticle = favoriteArticles[favoriteIndex] , it outputs : [null, null, null, null, null, null, null, null, null, null]
"newArticle" is a variable local to the method, modifying it doesn't change anything outside of the method. Modifing it DOES clobber what value was passed in as a parameter. "favoriteArticles[favoriteIndex]" is null because it hasn't been set yet.
salvin francis wrote:First of all ... Welcome to coderanch !! We hope you have an amazing time here in your quest to learn coding !!
I think your program can explain itself. I have added a few print statements to your method setFavoriteArticle :
I suggest running this and letting us know if the output makes sense ;)
Hi!, thank you! I ran it and it explains well that the values at the given indexes are null and because of that the value of newArticle is changed to "null". Thank you so much for explaining this, I know it's a very stupid question, I just started learning java and my questions are silly.