• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Need some help regarding arraylist

 
Ranch Hand
Posts: 59
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,

ArrayList arrL = new ArrayList();
ArrayList tmpArrL = new ArrayList();

for (int i = 0; i < size; i++) {
Character ch = new Character(text.charAt(i));
arrL.add(ch);
}
tmpArrL = arrL;
------;
------;
String newText = "";
for (int i = 0; i < arrL.size(); i++) {
newText += tmpArrL.get(i);
}
return newText;

In some cases the arraylist contains around 500000 characters. in this situtation tool gets hanged and it takes alot of time to execute the for loop.

Please let me know how to handle this situation.

Thanks,
 
Greenhorn
Posts: 26
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
How about using StringBuffer instead of String for the concatenation?
 
Ranch Hand
Posts: 326
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
What is text (re: text.charAt(i))? It would appear to be a String, why would you need to parse a String into Characters, load them into an ArrayList then concatenate them all into to a String?
 
Ranch Hand
Posts: 809
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by Chethan Sharma:
In some cases the arraylist contains around 500000 characters. in this situtation tool gets hanged and it takes alot of time to execute the for loop.

Please let me know how to handle this situation.

Thanks,



500000 number of characters in a String and processing it by a for loop

What exactly is the source of this much number of characters? Is it from some file or from some socket you read that much characters?

Naseem
[ September 09, 2006: Message edited by: Naseem Khan ]
 
Ranch Hand
Posts: 1296
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I agree with Ray, what exactly are you trying to accomplish here?
 
Anay Nayak
Greenhorn
Posts: 26
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I guess Chetan gets the input in the form of a List of Character objects and the initial part of the code was just to create a dummy example?
 
Chethan Sharma
Ranch Hand
Posts: 59
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks alot.

I solved the problem using string buffer
reply
    Bookmark Topic Watch Topic
  • New Topic