Get list of attributes of an object in an List

前端 未结 8 1722
青春惊慌失措
青春惊慌失措 2020-12-12 19:12

When there is an List, is there a possibility of getting List of all person.getName() out of that? Is there an prepared call for that

8条回答
  •  旧巷少年郎
    2020-12-12 19:35

    I think you will always need to do that. But if you will always need such things, then I would suggest to make another class, for example call it People where personList is a variable.

    Something like this:

    class People{
        List personList;
        //Getters and Setters
    
        //Special getters
        public List getPeopleNames(){
             //implement your method here        
        }
    
        public List getPeopleAges(){
             //get all people ages here
        }
    }
    

    In this case you will need to call one getter only each time.

提交回复
热议问题