Thursday, 15 September 2011

Convert comma separated ArrayList value to String - Java -


I am trying to get string values ​​

  "one", " Two "," three "," four ",  

but what I currently get is

 " one "," two "," three , Four ",  

Here's the code, I have Arrayist value different than comma, but I want to take the value separated from that comma as two separate values And not as one.

Arreelist & lt; String & gt; List = New Arrestist & lt; String & gt; (); List.add ("a"); List.add ("two"); List.add ("three, four"); String list string = ""; (For string: list) {listString + = "\" "+ s +" \ ","; } System.out.println (listString);

Is this possible? If so, how do I do this?

Your problem is that the ArrayList will not be split automatically on the comma if you "three, four" If the array is added to the list, then a single entry will be added with the "three, four" value.

Therefore, you give an array of "three, four" divided method:

  string [] string = "three, four" .split (","); List.add (wire [0]); List.add (wire [1]);  

Keep in mind that the argument of split method is a regular expression - in this case there will be no difference, but it can be a catch in some situations.

>

No comments:

Post a Comment