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!
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