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?
Hi,
I'm not sure if this is possible, but is there a way to convert an ArrayList Element into a String?
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
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);
}
}
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.