split中文翻译(split())

导读 大家好,我是小科,我来为大家解答以上问题。split中文翻译,split()很多人还不知道,现在让我们一起来看看吧!1、Split 就是用来分解数组...

大家好,我是小科,我来为大家解答以上问题。split中文翻译,split()很多人还不知道,现在让我们一起来看看吧!

1、Split 就是用来分解数组的。 java.lang.string.split

2、split 方法

3、将一个字符串分割为子字符串,然后将结果作为字符串数组返回。

4、stringObj.split([separator,[limit]])

5、参数

6、stringObj

7、必选项。要被分解的 String 对象或文字。该对象不会被 split 方法修改。

8、separator

9、可选项。字符串或 正则表达式对象,它标识了分隔字符串时使用的是一个还是多个字符。如果忽

10、略该选项,返回包含整个字符串的单一元素数组。

11、limit

12、可选项。该值用来限制返回数组中的元素个数。

13、说明

14、split 方法的结果是一个字符串数组,在 stingObj 中每个出现 separator 的位置都要进行分解

15、。separator 不作为任何数组元素的部分返回。

16、示例1:

17、public class SplitDemo {

18、public static String[] ss=new String[20];

19、public SplitDemo() {

20、 String s = "The rain in Spain falls mainly in the plain.";

21、 // 在每个空格字符处进行分解。

22、 ss = s.split(" ");

23、}

24、public static void main(String[] args) {

25、 SplitDemo demo=new SplitDemo();

26、 for(int i=0;i<ss.length;i++)

27、 System.out.println(ss[i]);

28、}

29、}

30、程序结果:

31、The

32、rain

33、in

34、Spain

35、falls

36、mainly

37、in

38、the

39、plain.

40、示例2:

41、public class SplitDemo {

42、public static String[] ss=new String[20];

43、public SplitDemo() {

44、 String s = "The rain in Spain falls mainly in the plain.";

45、 // 在每个空格字符处进行分解。

46、 ss = s.split(" ",2);

47、}

48、public static void main(String[] args) {

49、 SplitDemo demo=new SplitDemo();

50、 for(int i=0;i<ss.length;i++)

51、 System.out.println(ss[i]);

52、}

53、}

54、程序结果:

55、The

56、rain in Spain falls mainly in the plain.

57、示例3:

58、public class SplitDemo {

59、public static String[] ss=new String[20];

60、public SplitDemo() {

61、 String s = "The rain in Spain falls mainly in the plain.";

62、 // 在每个空格字符处进行分解。

63、 ss = s.split(" ",20);

64、}

65、public static void main(String[] args) {

66、 SplitDemo demo=new SplitDemo();

67、 for(int i=0;i<ss.length;i++)

68、 System.out.println(ss[i]);

69、}

70、}

71、程序结果:

72、The

73、rain

74、in

75、Spain

76、falls

77、mainly

78、in

79、the

80、plain

本文到此讲解完毕了,希望对大家有帮助。

最新文章