Class Object vs Hashmap

后端 未结 3 967
悲哀的现实
悲哀的现实 2020-12-05 00:50

Is it good to use hashmap instead of using the object class...... Using Hashmap....

Map cellMap = new HashMap();
         


        
3条回答
  •  南方客
    南方客 (楼主)
    2020-12-05 01:05

    You should see this as a "design" issue before performance. No need to do upfront premature optimization in favour of good design. So, the question is: "do you need to go through an intermediary collection to populate your domain object ABC?" In most cases I wouldn't do it but it's hard to say a definitive yes or a definitive no without knowing the larger context.

    UPDATE: 30-40K: Number of records is irrelevant for the Object vs HashMap comparison because they're going to be handled in a loop (disclaimer: irrelevant in terms of design not in terms of performance). However the number of columns in your spreadsheet is important as this is going to be reflected directly as the number of attributes in your object.

    If this is just a data migration or data transfer exercise then I'd go with the HashMap approach. Assuming that ABC will be a short-lived, throwaway data container object without behaviour, there's no need to create it. Then I'd test the performance of the system and if it doesn't satisfy the acceptance criteria then I'd profile it and optimize it only if necessary.

提交回复
热议问题