'creating a new table from for loop in java

this is the list of table which is not same data type

-DataTableOne 
    int idOne;
    string name;

-DataTableTwo
    int idTwo;
    int id;

getter, setter and service is been implemented for this tow classes

now i have the list from DataTableOne like 10 records and want to create new DataTableTow in action

//i can not create the DataTableTow list by geting the loop from DataTableOne

List<DataTableOne> listOne = service.ListAll(); //will return 10 records
List<DataTableTwo> listTwo = null;

for(DataTableOne row : listOne){
   
   // how to add data of the DataTableOne and add it to the listTwo  

 }

thanks in advance.



Solution 1:[1]

//Entity class of the DataTableTwo was not correctly initialized.

List<DataTableOne> listOne = service.ListAll(); //will return 10 records
List<DataTableTwo> listTwo = null;

for(DataTableOne row : listOne){
   
   listTwo.add(new DataTableTwo(row.getIdOne(), 1)); //there are two integer and you can form any how you want.

 }

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 SAR