Results 1 to 6 of 6
- 05-04-2011, 01:04 AM #1
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??
Java Code:List<Integer> x = new ArrayList<Integer>(); for (int i = 0; i < Faces.length; i++) { x.add(Faces[i][0]); x.add(Faces[i][1]); x.add(Faces[i][2]); }Last edited by zenitis; 05-04-2011 at 01:07 AM.
- 05-04-2011, 01:10 AM #2
- Join Date
- Jan 2011
- Location
- Richmond, Virginia
- Posts
- 3,069
- Blog Entries
- 3
- Rep Power
- 7
What's the issue? This look like it should work. Are you getting errors? Incorrect output?
- 05-04-2011, 01:12 AM #3
Member
- Join Date
- May 2011
- Posts
- 14
- Rep Power
- 0
Newbie attempting to answer the question. Not sure I understand, but wouldn't it work as:
I meant int j = i - 1 =PJava Code:List<Integer> x = new ArrayList<Integer>(); for (int i = 0; i < Faces.length; i++) { j = i - 1; x.add(Faces[i][j]); }Last edited by Inferno719; 05-04-2011 at 01:25 AM.
- 05-04-2011, 01:13 AM #4
: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 #5
- Join Date
- Jan 2011
- Location
- Richmond, Virginia
- Posts
- 3,069
- Blog Entries
- 3
- Rep Power
- 7
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
where the key is the integer found, and the value is the count of that integer.Java Code:Map<Integer, 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
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.Java Code:x.add(Faces[i][j]);
- 05-04-2011, 09:01 AM #6
Easy guys for the sake of java. What i finally try to do it is something like that
Ignore the most code my finally I have a different list x every iteration and I want to parse it in the 2DarrayList conVert so I use the conVert.add(x); but my problem is on x.clear();. When I print conVert before clear conVert is ok but when i print it after clear besides x also and conVert is cleared. What can I do for this?Java 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) { x.add(Faces[i][0]); x.add(Faces[i][1]); x.add(Faces[i][2]); } } } removeDuplicateWithOrder((ArrayList) x); valenceList.add(x.size() -1); conVert.add(x); System.out.println(conVert); x.clear(); //System.out.println(conVert); }
Similar Threads
-
how to add Arraylist filter for a jsp page showing results from a servlet-Arraylist
By alok_sharma in forum Java ServletReplies: 7Last Post: 11-22-2010, 01:26 PM -
Multiple lines in arrayList
By Lund01 in forum Advanced JavaReplies: 6Last Post: 10-15-2010, 12:34 PM -
Add Matices in ArrayList <Matrix>?
By spatel14 in forum New To JavaReplies: 19Last Post: 04-07-2010, 10:49 AM -
[SOLVED] Writing ArrayList to Text File on seperate Lines
By shinjitsunohana in forum New To JavaReplies: 9Last Post: 08-27-2008, 05:53 PM -
Help with matrix
By susan in forum New To JavaReplies: 1Last Post: 08-07-2007, 04:37 AM


LinkBack URL
About LinkBacks
Reply With Quote
Bookmarks