Welcome to Software Development on Codidact!
Will you help us build our independent community of developers helping developers? We're small and trying to grow. We welcome questions about all aspects of software development, from design to code to QA and more. Got questions? Got answers? Got code you'd like someone to review? Please join us.
Post History
Each list index refers to the same HashMap which it just override the key's value with each iteration of your loop, losing any previously set values. So if I put the HashMap value inside loop then ...
Answer
#1: Initial revision
Each list index refers to the same `HashMap` which it just override the key's value with each iteration of your loop, losing any previously set values. So if I put the HashMap value inside loop then it works fine. So the code will look like ```java while(c.moveToNext()){ HashMap<String, String> data = new HashMap<>(); phoneNumber = c.getString(c.getColumnIndex(CallLog.Calls.NUMBER)); type = c.getString(c.getColumnIndex(CallLog.Calls.TYPE)); date = c.getString(c.getColumnIndex(CallLog.Calls.DATE)); duration = c.getString(c.getColumnIndex(CallLog.Calls.DURATION)); name = c.getString(c.getColumnIndex(CallLog.Calls.CACHED_NAME)); data.put(Constants.PHONE_NUMBER, phoneNumber); data.put(Constants.NAME, name); data.put(Constants.DATE, date); data.put(Constants.TYPE, type); data.put(Constants.DURATION, duration); callLog.add(data); } ```