How to get Output as an Array


Through my Spring Boot Application, I’m displaying some engagement messages for the users. I save the values into the Array and display them randomly. But, now admin can also enter the Engagement Messages. So, I created an endpoint to get those values.

Now, I need to query the messages provided by admins and include them with the array I already have.


//my Previous Hard-Coded values
    private String loadScreenOne = "Have a great day!";
    private String loadScreenTwo = "Its a great day to start a new group for a new great goal!";

//dto for the Admins' Inputs
//Here EngagementMessageType is an Enum since messages will be show according to the users' current scrren
    private EngagementMessageType messageType;
    private String loadScreen;
    private String userCreation;

    EngagementMessages engagementMessages = new EngagementMessages();
            String[] randomArray = {engagementMessages.getLoadScreenOne(), engagementMessages.getLoadScreenTwo(), engagementMessages.getLoadScreenThree(), engagementMessages.getLoadScreenFour(),
                    engagementMessages.getLoadScreenFive(), engagementMessages.getLoadScreenSix(), engagementMessages.getLoadScreenSeven()};
            Random random = new Random();
            int randomNumber = random.nextInt(randomArray.length);
            return randomArray[randomNumber];
//It's my RepositoryImpl here I need to query the messages according to their type and include them into this array.

Can someone help me to solve this issue?