Memory overhead of Java HashMap compared to ArrayList

If you’re comparing HashMap with ArrayList, I presume you’re doing some sort of searching/indexing of the ArrayList, such as binary search or custom hash table…? Because a .get(key) thru 6 million entries would be infeasible using a linear search. Using that assumption, I’ve done some empirical tests and come up with the conclusion that “You … Read more

Can not deserialize instance of java.util.ArrayList out of VALUE_STRING

This is the solution for my old question: I implemented my own ContextResolver in order to enable the DeserializationConfig.Feature.ACCEPT_SINGLE_VALUE_AS_ARRAY feature. package; import; import; import; import; import; import; @Produces(MediaType.APPLICATION_JSON) @Provider public class ObjectMapperProvider implements ContextResolver<ObjectMapper> { ObjectMapper mapper; public ObjectMapperProvider(){ mapper = new ObjectMapper(); mapper.configure(DeserializationConfig.Feature.ACCEPT_SINGLE_VALUE_AS_ARRAY, true); } @Override public … Read more

How can I convert ArrayList to ArrayList?

Since this is actually not a list of strings, the easiest way is to loop over it and convert each item into a new list of strings yourself: List<String> strings = .map(object -> Objects.toString(object, null)) .toList(); Or when you’re not on Java 16 yet: List<String> strings = .map(object -> Objects.toString(object, null)) .collect(Collectors.toList()); Or … Read more