Need some help regarding arraylist [message #178791] |
Sat, 09 September 2006 12:22  |
Eclipse User |
|
|
|
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,
|
|
|
Re: Need some help regarding arraylist [message #178805 is a reply to message #178791] |
Sat, 09 September 2006 13:05  |
Eclipse User |
|
|
|
On Sat, 09 Sep 2006 12:22:28 -0400, Sarayu Geethajali =
<sarayu_geetha@yahoo.com> wrote:
> Hi,
>
> ArrayList arrL =3D new ArrayList(); ArrayList tmpArrL =3D new ArrayLis=
t();
>
> for (int i =3D 0; i < size; i++) {
> Character ch =3D new Character(text.charAt(i));
> arrL.add(ch);
> }
> tmpArrL =3D arrL; ------;
> ------;
> String newText =3D "";
> for (int i =3D 0; i < arrL.size(); i++) {
> newText +=3D 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 f=
or =
> loop. Please let me know how to handle this situation.
>
> Thanks,
>
This is not a webtools quesion, just a plain java question, so there mig=
ht =
be more
appropriate newgroups for you to join ... but to offer one suggestion,
you should use StringBuffer, instead of creating so many new Strings wit=
h
newText +=3D tmpArrL.get(i)
|
|
|
Powered by
FUDForum. Page generated in 0.03608 seconds