Go Back   CodingForums.com > :: Server side development > Java and JSP

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rate Thread
Old 11-03-2009, 04:01 PM   PM User | #1
edzillion
New Coder

 
Join Date: Apr 2008
Posts: 13
Thanks: 0
Thanked 0 Times in 0 Posts
edzillion is an unknown quantity at this point
large arraylist running out of memory, options?

Hi

I have a program that needs to load a very large csv file (2meg file, 192718 items) - I have a loop going through adding each item to as a new arraylist item.

Code:
while ((line = bufRdr.readLine()) != null) {
				StringTokenizer st = new StringTokenizer(line, "\n");
				while (st.hasMoreTokens()) {
					// get next token and store it in the array
					String word = st.nextToken().toUpperCase();
					boolean containsApostrophe = false;
					if(word.indexOf('\'') != -1)
						containsApostrophe = true;
					if (word.length() > 3 && !containsApostrophe)
					{
						char[] wordCh = word.toCharArray();
						Word newWord = new Word(wordCh);
						words.add(newWord);
						System.out.println(words.size());
					}
				}
			}
After about 17 thousand the console (in eclipse) starts displaying memory addresses and nothing else, eg:

com.package.example.Word@1e41969, com.package.example.Word@407d11

etc.

I would like to take all these in once, and then save them (as an arraylist) to a file so I don't have to do it again. What are my options?
edzillion is offline   Reply With Quote
Old 11-04-2009, 01:23 AM   PM User | #2
cs_student
New Coder

 
Join Date: Oct 2009
Location: ~/
Posts: 61
Thanks: 1
Thanked 8 Times in 8 Posts
cs_student is an unknown quantity at this point
If you already know the amount of items you are going to be storing, it would be wise to set the initial capacity of the ArrayList to keep from having to dynamically resize the array.

Why not just use an String instead of a Word class?
You should post the code for the word class so we can inspect that, as we don't know how it's implemented.

Also, the StringTokenizer class is deprecated. You should look into using the Scanner class instead.
cs_student is offline   Reply With Quote
Reply

Bookmarks

Jump To Top of Thread


Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 05:12 AM.

Home - Contact Us - Archives - Link to CF - Resources - Top 

Powered by vBulletin® Version 3.8.2
Copyright ©2000 - 2009, Jelsoft Enterprises Ltd.