Junior — Middle
Can you explain what is meant by mapping in programming?
sobes.tech AI
Answer from AI
In programming, the term "mapping" usually refers to the process of transforming data from one form or structure to another. For example, it could be converting an object of one class into an object of another class, corresponding to a different layer of the application (DTO, Entity, etc.).
Example: you have a list of numbers, and you want to get a list of their squares — this is also mapping:
List<Integer> numbers = Arrays.asList(1, 2, 3, 4);
List<Integer> squares = numbers.stream()
.map(n -> n * n)
.collect(Collectors.toList());
Here, the map method transforms each element of the original list into a new element, creating a new collection with the transformed values.