Skip to content
Advertisement

How to push value in List of Object?

A problem occurred while the Java project was in progress, so I asked a question.

For example, suppose we have this Object in JavaScript.

JavaScript

I can add a value to the food array.

JavaScript

Like javascript, java directly pushes a value to a list of objects.

JavaScript

Is there any way other than to declare ArrayList in advance using call by reference and put it in testObject?

Advertisement

Answer

As of java 8+ you can try something like this:

JavaScript
User contributions licensed under: CC BY-SA
4 People found this is helpful
Advertisement