Hello guys, I'm here with a new code I'm trying to make that I cannot get it out of my head :rage: So, here's my problem: I have two tables with information. Both of them have the same structure (ID, Value) but one of them has more repeated values than the other one. For example: |----------------------| |----------------------|
| ID Val | | ID Val |
|----------------------| |----------------------|
| 1 0 | | 1 0 |
| 1 0 | | 1 0 |
| 2 5 | | 1 0 |
| 2 5 | | 1 0 |
| 2 5 | | 2 5 |
| 2 5 | | 2 5 |
| 3 1 | | 2 5 |
| 3 1 | | 2 5 |
----------------------- | 3 1 |
| 3 1 |
------------------------
Here you can see two tables with the same structure but one of them has more repeated values than the other one (as I said before). What I'm trying to make, is the following: take the ID from the first table (ID = 1) and copy the value from the second table (Val = 0), but just copy it as many times as the ID in the first table exists. For example: if the ID 1 in the first table exists 2 times, copy the Val from the second table 2 times, skip the other two, and go to the next ID by doing the same.
I've tried to do it. The class I've made loads both tables and fills two ArrayLists with its information by putting them into an IntIntHolder class (thks aCis) in order to compare them later. So far, this is the code I've written, but it throws NoSuchElementException. And running it without the (see below), it prints some data but not all (if total data is 8, it prints 4).
while (elementA.getId() != elementB.getId())
Here's my code:
public void compareAndPrint()
{
Iterator<IntIntHolder> iterA = listA.iterator();
Iterator<IntIntHolder> iterB = listB.iterator();
while (listA.hasNext())
{
IntIntHolder elementA = iterA.next();
IntIntHolder elementB = iterB.next();
if (elementA.getId() == elementB.getId())
System.out.println(elementB.getValue());
else
{
while (elementA.getId() != elementB.getId())
iterB.next();
}
}
}
So ye... that's all. I'm trying to parse some data from the system so that's why I'm trying to do this.
Thanks for reading, and I'm looking forward to your answers!
Lineage2 Acessen- INTERLUDE PVP-PVE LOW CLASSIC
RETAIL SERVER !!
💫 NPC BUFFER SENCILLO A PARTIR DE LVL 20
Exp x1.50 | Adena x1.50
Sistema de Casas por alquiler ( incluyen niveles para mejorar la casa + beneficios )
Sistema de tradeo mediante buffalo ( transporte de items de ciudad a ciudad, con ganancia de adena ).
Website: acessen.com.ar
Discord: https://discord.gg/jzyyQtEKmf PARA MAS INFORMACIÓN
🎯 Looking for a stable and fun server to grind with your friends?
Join L2Roosters over 1000+ players online daily, intense epic battles, fair economy, no corruption, and exciting daily events!
💎 Got friends? Bring them along and claim 1 WEEK of FREE Premium Access!
🔥 Start your journey with us today!
Hey everyone!
L2Evolution – Inspired by L2Pride
We’ve just released more info about the server everything you need to know is now available!
👉 Learn more here: https://l2evolution.org/Forum/wiki/
🌐 Official Website: l2evolution.org
Question
Alianza
Hello guys,
I'm here with a new code I'm trying to make that I cannot get it out of my head :rage:
So, here's my problem: I have two tables with information. Both of them have the same structure (ID, Value) but one of them has more repeated values than the other one. For example:
|----------------------| |----------------------|
| ID Val | | ID Val |
|----------------------| |----------------------|
| 1 0 | | 1 0 |
| 1 0 | | 1 0 |
| 2 5 | | 1 0 |
| 2 5 | | 1 0 |
| 2 5 | | 2 5 |
| 2 5 | | 2 5 |
| 3 1 | | 2 5 |
| 3 1 | | 2 5 |
----------------------- | 3 1 |
| 3 1 |
------------------------
Here you can see two tables with the same structure but one of them has more repeated values than the other one (as I said before). What I'm trying to make, is the following: take the ID from the first table (ID = 1) and copy the value from the second table (Val = 0), but just copy it as many times as the ID in the first table exists. For example: if the ID 1 in the first table exists 2 times, copy the Val from the second table 2 times, skip the other two, and go to the next ID by doing the same.
I've tried to do it. The class I've made loads both tables and fills two ArrayLists with its information by putting them into an IntIntHolder class (thks aCis) in order to compare them later. So far, this is the code I've written, but it throws NoSuchElementException. And running it without the (see below), it prints some data but not all (if total data is 8, it prints 4).
Here's my code:
So ye... that's all. I'm trying to parse some data from the system so that's why I'm trying to do this.
Thanks for reading, and I'm looking forward to your answers!
7 answers to this question
Recommended Posts