0
I have a List1 and a List2. List1 is very large and List2 has some elements of List1. To avoid searching the entire List1 to make a modification and thus lose performance, I need to have a List2 in which I can change the data in a way that also changes in List1.
Example: my list one has 250000 elements. I need to change element 210100. If I can do this by changing a second list where I only have the data that I will change in the future, I gain more performance.
How can I do that?
Do you want to create a copy of the List and keep it up to date? Why do you want to do this?
– Douglas
In this case it would be a copy, but actually I have a List1 and a List2. List1 is very large and List2 has some elements of List1. To avoid searching the entire List1 to make a modification and thus lose performance, I need to have a List2 in which I can change the data in a way that also changes in List1.
– Marcos Vinicius
Example: my list one has 250000 elements. I need to change element 210100. If I can do this by changing a second list where I only have the data that I will change in the future, I gain more performance.
– Marcos Vinicius
You’d better put that information in the question, as it is you might get answers that don’t suit you.
– Douglas
You’re right. I’ve already changed my question to make it clearer. Thanks for the tip.
– Marcos Vinicius
Have you thought about making List2 a Map<Integer, Object> that has as key the index of List1 (the "address") and as value the Item that is in List1 in this Index?
– Douglas
Do you say Hash table? I’ve never heard of Map. Can I search about.
– Marcos Vinicius
What kind of data are you saving to List?
– Sorack
My Linkedlist is as follows:
public LinkedList<Evento> eventos = new LinkedList<>();
Where in Event I have getters and setters for my data as price, for example. Such list is loaded with about 250,000 positions. I have a second list,public LinkedList<Evento> usuario = new LinkedList<>()
, which should hold some positions of the first one for me to modify when necessary, without going through the first one in full.– Marcos Vinicius
@Douglas Table Hash is a data structure that can be used to implement, among other things, the abstract type Map. The concept is one thing and the implementation is another. Similarly, Linkedlist is an implementation of the List concept using pointers, but there are other ways to do it. It is always interesting to think in the most abstract way possible, not to get stuck to implementation details.
– Pablo Almeida