-3

I'm getting from JSON string like this:

{
  "name":"Google"
  "items": "item1,item2,item3,item4"
}

So I want to create array String[] items and populate it with items from this string. I need somehow to cut this string in parts. Also I'm getting different number of items, not only 4, like in example.

How can I do this....?

KiKo
  • 1,668
  • 7
  • 27
  • 56
  • 1
    possible duplicate of [How to split a String in Java](http://stackoverflow.com/questions/3481828/how-to-split-a-string-in-java) – Anarki Nov 28 '14 at 14:53
  • Shows us the whole JSON string ! – Anarki Nov 28 '14 at 14:54
  • 1
    In general, try to google this very basic stuff first. Chances are very, very low that no one before you tried to split a string and posted it online. – luuksen Nov 28 '14 at 15:06

3 Answers3

2
String[] items = incomingString.split(",");
luuksen
  • 1,357
  • 2
  • 12
  • 38
2

Look at String.split() you can pass in a char that will split up your string and return an array

Ryan Sayles
  • 3,389
  • 11
  • 56
  • 79
1

are you looking for the below line or I misunderstood your question ?

String[] result = yourString.split(",");
Kent
  • 189,393
  • 32
  • 233
  • 301