0

If I have a string.

String msg = "I love mickey mouse";

What method can I used to display the string, "mickey"?

7
Contributors
9
Replies
10
Views
7 Years
Discussion Span
Last Post by java_programmer
0

Try to read documentation for the method public String substring(int beginIndex, int endIndex)

0

我会用 String[] split(String regex) 得到一个关于这个字符串的字符串数组

public String getStringMickey(){
       String msg = "I love mickey mouse"; 
       String[] str = msg.split(" ");
       return str[2];
}
0

我会用 String[] split(String regex) 得到一个关于这个字符串的字符串数组

public String getStringMickey(){
       String msg = "I love mickey mouse"; 
       String[] str = msg.split(" ");
       return str[2];
}

Why str[2]?

0

Read the API doc for the split() method.
Where (what index) in the array returned by split() would the desired word be?

0

不知道楼上的意思是什么,回答引用人的问题:
String str[] = msg.split(" ");
这里的str是一个String数组,里面装的是{"I","love","mickey","mouse"}
now, do u know why str[2] 了吗?

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.