HashMap alternatives for memory-efficient data storage

前端 未结 10 1451
逝去的感伤
逝去的感伤 2020-12-24 06:50

I\'ve currently got a spreadsheet type program that keeps its data in an ArrayList of HashMaps. You\'ll no doubt be shocked when I tell you that this hasn\'t proven ideal.

10条回答
  •  孤城傲影
    2020-12-24 07:27

    From your description, it seems that instead of an ArrayList of HashMaps you rather want a (Linked)HashMap of ArrayList (each ArrayList would be a column).

    I'd add a double map from field-name to column-number, and some clever getters/setters that never throw IndexOutOfBoundsException.

    You can also use a ArrayList> (basically a jagged dinamically growing matrix) and keep the mapping to field (column) names outside.

    Some columns will have a lot of repeated values

    I doubt this matters, specially if they are Strings, (they are internalized) and your collection would store references to them.

提交回复
热议问题