类型转换
类型之间的相互转换
哭哭啼
这个作者很懒,什么都没留下…
展开
-
遍历字符串每个字符
public static void main(String[] args) { String str = "123\\n456\\n789\\n+0- qwertyuiopasdfghjklzxcvbnm是谁?!@#"; for (int i = 0; i < str.length(); i++) { System.out.println(str.charAt(i)); } }原创 2022-03-10 16:15:35 · 336 阅读 · 0 评论 -
数组和list之间的相互转换
数组和list之间的相互转换数组转list遍历Arrays.asList()方法(有局限)Collections.addAll()java8 stream流list转数组toArray()toArray(T[] a)(推荐)数组转list注意:在数组转list过程中,如果数组是8大基本数据类型,将数据类型转为对应的封装类,避免转换为list后存储元素是数组而不是数组的元素。遍历 int[] arr = {2, 0, 4, 9, 3, 6, 8, 7, 1, 5, 3};ArrayList<原创 2022-02-18 15:02:36 · 4672 阅读 · 0 评论 -
byte数组与字符串之间相互转换
byte数组与字符串之间相互转换字符串转数组数组转字符串使用String类利用16进制字符串字符串转数组 public static void main(String[] args) { String str="失败是成功之母!"; byte[] bytes = str.getBytes(StandardCharsets.UTF_8); }数组转字符串使用String类 public static void main(String[] args) thr原创 2022-02-15 16:52:09 · 29360 阅读 · 0 评论