-2
[email protected],[email protected],[email protected],[email protected]

I want to convert above string value as below using java.

["[email protected]","[email protected]","[email protected],"[email protected]"]

How I create it.

2 Answers2

1

You can use both Split() method of String class or StringTokenizer class to split String.

see below code.

package naveed.practice;

import java.util.Arrays;
import java.util.StringTokenizer;

public class Test {
public static void main(String[] args) {
    String s = "[email protected],[email protected],[email protected],[email protected]";
    System.out.println(Arrays.toString(s.split(",")));
    //OR
    StringTokenizer s1= new StringTokenizer(s, ",");
    while(s1.hasMoreElements())
    {
        System.out.println(s1.nextElement());
    }
}
}

Output:

[[email protected], [email protected], [email protected], 

[email protected]]
[email protected]
[email protected]
[email protected]
[email protected]
KhAn SaAb
  • 5,248
  • 5
  • 31
  • 52
0
String s="[email protected],[email protected],[email protected],[email protected]";
String[] arr= s.split(",");
Ahmad Sanie
  • 3,678
  • 2
  • 21
  • 56