2016-05-10 30 views
-2
[email protected],[email protected],[email protected],[email protected] 

javaを使用して上記の文字列値を次のように変換したいと思います。私はそれを作成する方法javaを使用して文字列を文字列に変換する方法

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

+0

[文字列の#分割](https://docs.oracle.com/javase/7/docs/api/java/lang/String.html# split(java.lang.String)) – SomeJavaGuy

+0

javaはsplitmethodを与え、正規表現に基づいて配列を取得できます。 – GvSharma

+0

public class StringSplit { public static void main(String [] args){ 文字列入力= "wpraneethmadusanka @ gmail.com、kavindapathum @ gmail.com、pathum123 @ gmail.com、danushka @ gmail.com"; // for(文字列curLine:入力) String [] parts = input.split( "、");for(int i = 0; i

答えて

1

Split()メソッドをStringクラスまたはStringTokenizerクラスを使用して、文字列を分割することができます。

以下のコードを参照してください。

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()); 
    } 
} 
} 

出力:

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

[email protected]] 
[email protected] 
[email protected] 
[email protected] 
[email protected] 
関連する問題