首页 > 编程语言 > 详细

1.7 字符串和字符数组的转换

时间:2017-05-10 00:05:59      阅读:286      评论:0      收藏:0      [点我收藏+]

 

package Demo;

public class Demo2 {
 public static void main(String[] args) {
  String str = "helloworld";
  char c[] = str.toCharArray(); //字符串转换为字符数组
  for(int x=0;x<c.length;x++){
   System.out.println(c[x]+"、");
   }
 /*h、
  e、
  l、
  l、
  o、
  w、
  o、
  r、
  l、
  d、*/
  System.out.println("\n"+ new String(c));//helloworld
  System.out.println(new String(c,0,5)); //输出hello    (c,0,5) 截取下标0-5的字符  前包括,后不包括
  
  
 }
 
 
}

1.7 字符串和字符数组的转换

原文:http://www.cnblogs.com/mengliang/p/6833268.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!