Java - Split and trim in one shot

后端 未结 8 1028
鱼传尺愫
鱼传尺愫 2020-12-13 23:25

I have a String like this : String attributes = \" foo boo, faa baa, fii bii,\" I want to get a result like this :

String[] result = {\"foo boo\         


        
8条回答
  •  情话喂你
    2020-12-14 00:01

    If there is no text between the commas, the following expression will not create empty elements:

    String result[] = attributes.trim().split("\\s*,+\\s*,*\\s*");
    

提交回复
热议问题