Null return when i run my code
hello, i completed a lesson but what it gave didn’t make a lot of sense. i wrote:

import java.util.Arrays;

public class Newsfeed {
  String[] topics = {"Opinion", "Tech", "Science", "Health"};
  int[] views = {0, 0, 0, 0};
  String[] favoriteArticles;
  public Newsfeed(){
    favoriteArticles = new String [10];
  public void setFavoriteArticle(int favoriteIndex, String newArticle){
    // Add newArticle to favoriteArticles:
    favoriteArticles[favoriteIndex] = newArticle;
  public static void main(String[] args){
    Newsfeed sampleFeed = new Newsfeed();
    sampleFeed.setFavoriteArticle(2, "Humans: Exterminate Or Not?");
    sampleFeed.setFavoriteArticle(3, "Organic Eye Implants");
    sampleFeed.setFavoriteArticle(0, "Oil News");

and got:

[Oil News, null, Humans: Exterminate Or Not?, Organic Eye Implants, null, null, null, null, null, null]

is this how its supposed to be?

Well, think about what the code is doing:

At one point you create an array of length 10 (favoriteArticles). It has 10 empty slots. Then you assign articles to slot 0, 2, and 3 (out of slots 0-9). The rest still have value to represent their existence.

If you want to see the whole array, you will see the null values, if you want to see only the filled slots, you’d have to call them specifically.

wow thanks that made sense. almost a duh thing.its just the unused spaces.