# Add lines of a matrix in arrayList

• 05-04-2011, 01:04 AM
zenitis
Add lines of a matrix in arrayList
Hello guys. I ve stuck to the following issue. Actually I m having a 2D array of integers 1850x3 and I want to create an new array using only lines which include a specific integer. I m trying to parse these lines into an arrayList but I ve got a few troubles. Any tips to solve out this problem??

Code:

List<Integer> x =  new ArrayList<Integer>();

for (int i = 0; i < Faces.length; i++) {

}

• 05-04-2011, 01:10 AM
sunde887
What's the issue? This look like it should work. Are you getting errors? Incorrect output?
• 05-04-2011, 01:12 AM
Inferno719
Newbie attempting to answer the question. Not sure I understand, but wouldn't it work as:

Code:

List<Integer> x =  new ArrayList<Integer>();

for (int i = 0; i < Faces.length; i++)
{
j = i - 1;
}

I meant int j = i - 1 =P
• 05-04-2011, 01:13 AM
zenitis
:cool: sorry my mistake the problem is already solved. Now I want to calculate the number of unique integer elements of the list. Any suggestions?
• 05-04-2011, 01:20 AM
sunde887
it may be helpful to use a map. A set will also allow you to have a unique list of all the elements. But no count. You can try doing something like
Code:

Map<Integer, Integer>
where the key is the integer found, and the value is the count of that integer.

Your attempt inferno doesn't declare j, it just refers to it. It wouldn't help. The op however; could have done something like
Code:

I believe the original post was a little edited though. Do your best yo help out around her inferno. If you are wrong, I or someone else will correct you. If the correction seems harsh don't take offense, just use it as a learning experience.
• 05-04-2011, 09:01 AM
zenitis
Easy guys for the sake of java. What i finally try to do it is something like that

Code:

List<Integer> x =  new ArrayList<Integer>();
List<Integer> valenceList =  new ArrayList<Integer>();
List<List<Integer>> conVert = new ArrayList<List<Integer>>();

for (int q = 1; q <= 2; q++) {

for (int i = 0; i < Faces.length; i++) {

for (int j = 0; j < 2; j++) {

if (Faces[i][j] == q) {