Hi mohammed,
find the code below for creating and adding object to entity as a list. You can create multiple objects and add to the arraylist.
// BEGIN USER CODE
ArrayList<IMendixObject> mylist = new ArrayList<IMendixObject>();
IMendixObject newobj = Core.instantiate(getContext(), ListObj);
newobj.setValue(getContext(), sam.MemberNames.num1.toString(), "2");;
mylist.add(newobj);
return mylist;
// END USER CODE
sam.MemberNames.num1.toString() – sam is an entity and num1 is attribute.
ListObj - the entity passed from the java action.
I have attached the screenshots of the java action and output. You can extend the code as you need, Hope it helps.