Results 1 to 6 of 6
Thread: Arraylists
- 01-30-2012, 03:59 PM #1
Member
- Join Date
- Dec 2011
- Location
- London
- Posts
- 11
- Rep Power
- 0
Arraylists
Hi I need some help with arraylists, I am trying to load a text file into an array list with the following method:
Java Code:public static ArrayList LoadFile(JTextArea src){ String line = ""; ArrayList data = new ArrayList(); try{ FileReader fr = new FileReader("Products.txt"); BufferedReader br = new BufferedReader(fr); while ((line = br.readLine()) != null){ src.append(line); src.append(System.getProperty("line.separator")); } }catch(FileNotFoundException fN) { fN.printStackTrace(); } catch(IOException e){ System.out.println(e); } return data;
Also the above arraylist is defined in a class, while the search and display is done in the MainFrame class.
Hope some one can show me to the right direction.
thanksLast edited by JosAH; 01-30-2012 at 04:57 PM. Reason: added [code] ... [/code] tags
- 01-30-2012, 04:46 PM #2
Member
- Join Date
- Oct 2011
- Posts
- 92
- Rep Power
- 0
Re: Arraylists
Well splitting it up into lines and placing it into the textarea is all well and good for displaying it. For searching through it I would highly reccomend concatenating it all into a string, and using the String API to help you find the method for looking for certain patterns. For looking for certain patterns in strings, I would HIGHLY recommend teaching yourself regular expressions :)
- 01-30-2012, 05:02 PM #3
- Join Date
- Sep 2008
- Location
- Voorschoten, the Netherlands
- Posts
- 14,421
- Blog Entries
- 7
- Rep Power
- 26
Re: Arraylists
A List has an indexOf( ... ) method; it searches the list and if an element is found, its index is returned (otherwise -1 is returned). Read the API documentation for the List interface.
kind regards,
JosBuild a wall around Donald Trump; I'll pay for it.
- 01-30-2012, 05:13 PM #4
Member
- Join Date
- Oct 2011
- Posts
- 92
- Rep Power
- 0
- 01-30-2012, 05:44 PM #5
- Join Date
- Sep 2008
- Location
- Voorschoten, the Netherlands
- Posts
- 14,421
- Blog Entries
- 7
- Rep Power
- 26
- 01-30-2012, 06:44 PM #6
Member
- Join Date
- Dec 2011
- Location
- London
- Posts
- 11
- Rep Power
- 0
Similar Threads
-
help with ArrayLists !
By bigbreez21 in forum New To JavaReplies: 3Last Post: 11-20-2011, 08:23 PM -
ArrayLists
By Freakzoyd in forum New To JavaReplies: 4Last Post: 11-12-2010, 04:27 AM -
ArrayLists for BlueJ
By heyit'skaye in forum New To JavaReplies: 1Last Post: 09-01-2010, 04:15 AM -
arraylists problem
By newtojava7 in forum New To JavaReplies: 1Last Post: 03-12-2008, 07:38 AM
Bookmarks