String.split()问题

hztianye 2011-07-15 11:16:14
import java.util.Arrays;
class test4
{
public static void main(String[] args)
{
/*
int[] a={5,6,3,0};
Arrays.fill(a,0,3,1);
int[] b=Arrays.copyOf(a,6);
System.out.println(Arrays.toString(a));
*/
String str="hello world";

String[] inputStr= str.split(",");
for(String each:inputStr)
System.out.println(inputStr);

}
}
------------------------------------------------------
谁来解释一下输出结果为什么是[Ljava.lang.String;@de6ced
...全文
83 14 打赏 收藏 转发到动态 举报
写回复
用AI写文章
14 条回复
切换为时间正序
请发表友善的回复…
发表回复
iis81365341 2011-07-15
  • 打赏
  • 举报
回复
补充:
如:
String str = "aaa,bbb,ccc";
执行String[] inputStr= str.split(",");后

inputStr中的内容如下
inputStr[0]="aaa";
inputStr[1]="bbb";
inputStr[2]="ccc";
iis81365341 2011-07-15
  • 打赏
  • 举报
回复
[Quote=引用 12 楼 hztianye 的回复:]
谁解释一下这个语句有什么作用?
String[] inputStr= str.split(",");
[/Quote]以“,”分隔字符串,并保存为数组。
hztianye 2011-07-15
  • 打赏
  • 举报
回复
谁解释一下这个语句有什么作用?
String[] inputStr= str.split(",");
hztianye 2011-07-15
  • 打赏
  • 举报
回复
String[] inputStr= str.split(",");

好像没有什么作用,还是输出原来的字符串。
oo194900 2011-07-15
  • 打赏
  • 举报
回复
...老大你放进去一个指针当然打印出来的就是一个地址了...
哎呦喂哈 2011-07-15
  • 打赏
  • 举报
回复
[Quote=引用 4 楼 username_fb 的回复:]
O(∩_∩)O哈哈~
这都能错!改为:System.out.println(each);
[/Quote]

呵呵
zn85600301 2011-07-15
  • 打赏
  • 举报
回复
String[] inputStr 你直接输出对象 当然就是这样
iis81365341 2011-07-15
  • 打赏
  • 举报
回复
这个是由于粗心造成的低级错误。

[Ljava.lang.String;@de6ced表示hashCode为de6ced的String数组。
HeiBoyYang 2011-07-15
  • 打赏
  • 举报
回复
方案2 String str="hello,world,you";
String[] inputStr= str.split(",");
for(String each:inputStr)
System.out.println(each);
HeiBoyYang 2011-07-15
  • 打赏
  • 举报
回复
这样答应肯定不行出来的只是内存地址 这样你看看如下:
String str="hello,world,you";
String[] inputStr= str.split(",");
for(int i=0;i<inputStr.length;i++){
System.out.println(inputStr[i]);
}
USERNAME_FB 2011-07-15
  • 打赏
  • 举报
回复
O(∩_∩)O哈哈~
这都能错!改为:System.out.println(each);
zl3450341 2011-07-15
  • 打赏
  • 举报
回复
System.out.println(inputStr);改成
System.out.println(each);

结账 吧
飞跃颠峰 2011-07-15
  • 打赏
  • 举报
回复

System.out.println(inputStr);改成
System.out.println(each);
树成 2011-07-15
  • 打赏
  • 举报
回复
你应该使用System.out.println(each) 呆瓜

62,614

社区成员

发帖
与我相关
我的任务
社区描述
Java 2 Standard Edition
社区管理员
  • Java SE
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧