JAVA集合框架 试题?
发布网友
发布时间:2022-02-28 14:23
我来回答
共1个回答
热心网友
时间:2022-02-28 15:53
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
public class {
public () {
}
public Map<String, String> splitMail(List<String> mails) {
String userName;
String mailUrl;
Map<String, String> hp = new HashMap<String, String>();
for (String mail : mails) {
int first = mail.indexOf("@");
userName = mail.substring(0, first);
mailUrl = mail.substring(first, mail.length());
System.out.println(" 分离后的用户名:" + userName + "\n" + "分离后的邮箱地址:"
+ mailUrl);
hp.put(userName, mailUrl);
}
return hp;
}
public static void main(String[] args) {
List<String> mails = new ArrayList<String>();
mails.add("aa@sina.com");
mails.add("bb@163.com");
mails.add("cc@sohu.com");
Map<String, String> map = new ().splitMail(mails);//这个map就是你要的map了
}
}
---------------------------------------
2.
import java.util.ArrayList;
import java.util.List;
public class {
public () {
}
public static void main(String[] args) {
List<> list = new ArrayList<>();
for (int i = 0; i < 10; i++) {
list.add(new ());
}
//list就是你要的了
}
}
祝,好运!