我有一个返回 String
的方法。名为 contact
的字符串由多个较小的字符串组成。那些较小的字符串是该方法的参数。
例子:
String contact = id + " " + name + " " + telNum;
return contact;
现在我有另一种方法将 contact
作为参数,但它只需要返回名称。
所以我的问题是如何将较小的字符串 name
从整个字符串联系人中分离出来?
最佳答案
使用
String[] splits = contact.split(" ");
String name = splits[1];
关于java - 如何隔离字符串的一个组件?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36326165/