Results 1 to 6 of 6
Thread: Array vs ArrayList
- 10-14-2010, 09:06 AM #1
- 10-14-2010, 09:43 AM #2
Moderator
- Join Date
- Apr 2009
- Posts
- 10,484
- Rep Power
- 16
What do you mean by "better"?
Does your current code work?
Is it easy to understand?
- 10-14-2010, 09:47 AM #3
Found it.
I decided to use an arraylist, only to find a small problem.
I am reading in a file that contains 2 lines.
>HSIBIYG
>OHOUBO7
But he only adds line 1 to the arrayList.
Java Code:// Create Scanner for file1. Scanner x = new Scanner(file1); // We read the lines one by one in the file. // Keeps track of the count after something has been found. int getal = 0; // Count the number of lines. if (getal > 0) { getal++; } if (x.hasNextLine()) { String line = x.nextLine(); // Het ingelezen bestand word geprint. System.out.println(line); // ++ adds +1 every line. getal++; // We put what is in file1 into an arrayList. arrayList.add(line); System.out.println(arrayList); }
- 10-14-2010, 09:59 AM #4
Moderator
- Join Date
- Apr 2009
- Posts
- 10,484
- Rep Power
- 16
That has nothing to do with ArrayList and everything to do with the fact you are only adding one line to it.
That's an 'if' statement, not a loop, so it'll only execute once.
- 10-14-2010, 10:02 AM #5
I first had a while and not an if.
But then he prints my other while loop 2 times.
- 10-14-2010, 10:41 AM #6
Moderator
- Join Date
- Apr 2009
- Posts
- 10,484
- Rep Power
- 16
Similar Threads
-
2D array of ArrayList (technically a 3D array)
By Lil_Aziz1 in forum New To JavaReplies: 3Last Post: 05-15-2010, 08:11 PM -
Array and arraylist
By MIA6 in forum New To JavaReplies: 3Last Post: 11-29-2009, 02:22 AM -
[SOLVED] Should I use an arraylist or an array?
By matzahboy in forum New To JavaReplies: 5Last Post: 11-17-2008, 04:34 AM -
ArrayList versus Array
By junpogi in forum New To JavaReplies: 13Last Post: 11-08-2008, 02:04 AM -
Array to ArrayList
By javaplus in forum New To JavaReplies: 2Last Post: 11-12-2007, 12:46 AM


LinkBack URL
About LinkBacks
Reply With Quote
Bookmarks