Click to See Complete Forum and Search --> : concatenating strings


Rabbit3cat
03-05-2006, 04:16 PM
I am trying to add the elements in a list to the end of a string using concat, but it is not working for me. Below is the code i have written

import java.util.*;
public class concat {
public static void main(String[] args) {

String hello = "hello";
List list1 = new ArrayList();
list1.add("one");
list1.add("two");
list1.add("three");
Iterator iter = list1.iterator();
while(iter.hasNext()) {
Object e = iter.next();
System.out.println(e.toString());
hello.concat(e.toString());
}


System.out.println(hello);
}
}


Can anybody see why this is not working?
Thanks

Mr. Ram
03-06-2006, 02:33 AM
import java.util.*;
public class concat {
public static void main(String[] args) {

StringBuffer hello = new StringBuffer("hello"); List list1 = new ArrayList();
list1.add("one");
list1.add("two");
list1.add("three");
Iterator iter = list1.iterator();
while(iter.hasNext()) {
Object e = iter.next();
System.out.println(e.toString());
hello.append(e.toString());
}

System.out.println("hello : " + hello);
}
}