-8

On developing an Android project I have got stacked in position

I don't want to describe because it is simple.

String str = "Physics,Chemistry,Biology"

This is my String and three queries are divided by comma. One of my method returns string like this.

So I want to make it to a string array. This will like that dividing comma based.

String[] strArr = {"Physics", "Chemistry", "Biology"};
yivi
  • 42,438
  • 18
  • 116
  • 138
AA Shakil
  • 538
  • 4
  • 14

2 Answers2

1

there is a method in String class that can help you convert it, but you should give this method the regex , in your case regex is ","

you can use this method to convert it:

   public String[] convertToArray(String str, String regex){
    return str.split(regex);
   }

   String[] str = convertToArray(str, ",");
0

String[] strArr = str.split(“,”);

Subrata Mondal
  • 822
  • 7
  • 17
  • Thanks. I have another String array String[] subjects = {}; I want that the splitted array will replace it. – AA Shakil Jan 07 '18 at 18:02