-8

Convert the string: "(id,created,employee(id,firstname,employeeType(id), lastname),location)" to the following output id created employee - id - firstname - employeeType -- id - lastname location

is there any optimistic solution available with using regular expression

Pras
  • 5
  • 4

1 Answers1

0
public static void main(String[] args) {
    String a = "(id,created,employee(id,firstname," + 
             "employeeType(id), lastname),location)";
    StringTokenizer tok = new StringTokenizer(a, "(), ");
    System.out.println("StringTokenizer example");
    while (tok.hasMoreElements()) {
        String b = (String)tok.nextElement();
        System.out.println(b);
    }
    System.out.println("Split example");
    String[] array = a.split("(),");
    for (String ii: array) {
         System.out.println(ii);
    }

 } 
}

Outputs

StringTokenizer example
id
created
employee
id
firstname
employeeType
id
lastname
location
Split example
(id
created
employee(id
firstname
employeeType(id)
lastname)
location)

You can add the hyphens.

Dakoda
  • 175
  • 7