将一个字符串转化成String[]数组,提供两种方法 文章目录 前言一、pandas是什么?二、使用步骤 1.引入库2.读入数据总结 前言 将字符串转化成数组提供两种方法: 1.split(""); 2.toCha
将字符串转化成数组提供两种方法:
1.split("");
2.toCharArry()方法;
将String s转化为String数组;
public class T1 { public static void main(String[] args) { String str="abcdefg"; String[] a=str.split(""); System.out.println(Arrays.toString(a)); }}
>:[a, b, c, d, e, f, g]
public class T1 { public static void main(String[] args) { String str="a bc de g"; String[] a=str.split(" "); System.out.println(Arrays.toString(a)); }}
>:[a,bc,de,g]
如果要使用多个标记隔开时,使用|
public class T1 { public static void main(String[] args) { String str="a@bc de g"; String[] a=str.split("@| "); System.out.println(Arrays.toString(a)); }}
>:[a, bc, de, g]
将String s转化为Char数组:
public class T1 { public static void main(String[] args) { String str="ab cd efg adf"; char[] a=str.toCharArray(); System.out.println(Arrays.toString(a)); }}
>:[a, b, , c, d, , e, f, g, , a, d, f]
不会删掉所给字符串的空格
将字符串转化为Sting数组时,可以使用split()
将字符串转化为char数组时,可以使用toCharArry()
来源地址:https://blog.csdn.net/weixin_55519918/article/details/127547325
--结束END--
本文标题: Java将字符串转化为数组
本文链接: https://www.lsjlt.com/news/416161.html(转载时请注明来源链接)
有问题或投稿请发送至: 邮箱/279061341@qq.com QQ/279061341
下载Word文档到电脑,方便收藏和打印~
2024-04-03
2024-04-03
2024-04-01
2024-01-21
2024-01-21
2024-01-21
2024-01-21
2023-12-23
回答
回答
回答
回答
回答
回答
回答
回答
回答
回答
0