Converting an ArrayList Element into a String?

Hi,

I'm not sure if this is possible, but is there a way to convert an ArrayList Element into a String?

[117 byte] By [vopoa] at [2007-11-27 10:19:19]
# 1

Could you be a bit more vague, please.

CaptainMorgan08a at 2007-7-28 16:56:57 > top of Java-index,Java Essentials,Java Programming...
# 2

Have you tried toString() ?

If you need a String with the contents of the List then run a loop and concatenate the contents of the List into the String

ICE

icewalker2ga at 2007-7-28 16:56:57 > top of Java-index,Java Essentials,Java Programming...
# 3

I'm trying to create code, where a class calls upon the reform method.

When referencing this code, I want to use a string.

//List Sorted by title:

System.out.println("List Sorted by title: ");

ArrayList s = new ArrayList();

CollectionUtil c = new CollectionUtil();

c.reform();

-I want to add a string variable in c.reform(), where the reform method can modify the string.

In the reform method, I want to use a string parameter,

Here's my code:

public void reform()

{

//format input

ArrayList<String> list = new ArrayList<String>();

// a test

list.add("This");

list.add("is");

list.add("is");

list.add("a");

list.add("a");

list.add("test");

displayList(list);

}

public void displayList(ArrayList<String> list)

{

System.out.println("The size is: " + list.size());

for (int i = 0; i < list.size(); i++)

{

String title = list.get(i);

System.out.println(title);

}

}

vopoa at 2007-7-28 16:56:57 > top of Java-index,Java Essentials,Java Programming...
# 4

Still no idea what you want. But since your list already holds Strings then there is no need to do any converting. Just get an element back out.

floundera at 2007-7-28 16:56:57 > top of Java-index,Java Essentials,Java Programming...