Skip to content

将List处理成Map - #225

Open
3stonelei wants to merge 11 commits into
hcsp:masterfrom
3stonelei:master
Open

将List处理成Map#225
3stonelei wants to merge 11 commits into
hcsp:masterfrom
3stonelei:master

Conversation

@3stonelei

Copy link
Copy Markdown
  • 这个PR解答了当前仓库中的题目(机器人会自动判题并合并当前PR)
  • 这个PR修复了当前仓库中的一些代码缺陷(机器人不会判题,而是由管理员来处理当前PR)

@hcsp-bot

hcsp-bot commented Jun 4, 2022

Copy link
Copy Markdown
Contributor

🎉 感谢提交Pull Request!请稍等片刻,我们已经将其提交到CI进行检查,一旦有结果会立即通知您!

import java.util.Arrays;
import java.util.List;
import java.util.Map;
import java.util.*;

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

不应使用 '.*' 形式的导入 - java.util.* 。

// 市场部 -> [{name=王五, department=市场部, age=40 }]
public static Map<String, List<User>> collect(List<User> users) {}
public static Map<String, List<User>> collect(List<User> users) {
Map<String,List<User>> userListByDepartment=new HashMap<>();

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

',' 后应有空格。
'=' 后应有空格。
'=' 前应有空格。

Map<String,List<User>> userListByDepartment=new HashMap<>();
for (User user:users
) {
if (!userListByDepartment.containsKey(user.getDepartment())){

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

'{' 前应有空格。

for (User user:users
) {
if (!userListByDepartment.containsKey(user.getDepartment())){
userListByDepartment.put(user.getDepartment(),new ArrayList<>());

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

',' 后应有空格。

userListByDepartment.get(user.getDepartment()).sort(new Comparator<User>() {
@Override
public int compare(User o1, User o2) {
if (o1.getAge()==o2.getAge()){

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

'==' 后应有空格。
'==' 前应有空格。
'{' 前应有空格。


@Override
public String toString() {
return "User{" +

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

'+' 应另起一行。

@Override
public String toString() {
return "User{" +
"id=" + id +

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

'+' 应另起一行。

public String toString() {
return "User{" +
"id=" + id +
", name='" + name + '\'' +

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

'+' 应另起一行。

return "User{" +
"id=" + id +
", name='" + name + '\'' +
", age=" + age +

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

'+' 应另起一行。

"id=" + id +
", name='" + name + '\'' +
", age=" + age +
", department='" + department + '\'' +

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

'+' 应另起一行。

@hcsp-bot

hcsp-bot commented Jun 4, 2022

Copy link
Copy Markdown
Contributor

你的提交 b33827b ,似乎失败了:Your tests failed on CircleCI

😅 请不要气馁,仔细分析原因,再接再厉!

1 similar comment
@hcsp-bot

hcsp-bot commented Jun 4, 2022

Copy link
Copy Markdown
Contributor

你的提交 b33827b ,似乎失败了:Your tests failed on CircleCI

😅 请不要气馁,仔细分析原因,再接再厉!

for (User user:users
) {
List<User> userList;
if (userListByDepartment.containsKey(user.getDepartment())){

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

'{' 前应有空格。

) {
List<User> userList;
if (userListByDepartment.containsKey(user.getDepartment())){
userList=userListByDepartment.get(user.getDepartment());

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

'=' 后应有空格。
'=' 前应有空格。

List<User> userList;
if (userListByDepartment.containsKey(user.getDepartment())){
userList=userListByDepartment.get(user.getDepartment());
}else {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

'}' 后应有空格。
'else' 前应有空格。

if (userListByDepartment.containsKey(user.getDepartment())){
userList=userListByDepartment.get(user.getDepartment());
}else {
userList=new ArrayList<>();

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

'=' 后应有空格。
'=' 前应有空格。

return (o1.getAge()>o2.getAge())?1:-1;
}
});
userListByDepartment.put(user.getDepartment(),userList);

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

',' 后应有空格。


@Override
public String toString() {
return "{" +

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

'+' 应另起一行。

@hcsp-bot

hcsp-bot commented Jun 4, 2022

Copy link
Copy Markdown
Contributor

你的提交 3e3191c ,似乎失败了:Your tests failed on CircleCI

😅 请不要气馁,仔细分析原因,再接再厉!

1 similar comment
@hcsp-bot

hcsp-bot commented Jun 4, 2022

Copy link
Copy Markdown
Contributor

你的提交 3e3191c ,似乎失败了:Your tests failed on CircleCI

😅 请不要气馁,仔细分析原因,再接再厉!

Map<String,List<User>> userListByDepartment=new HashMap<>();
for (User user:users
) {
String departmentKey=user.getDepartment();

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

'=' 后应有空格。
'=' 前应有空格。

for (User user:users
) {
String departmentKey=user.getDepartment();
if (!userListByDepartment.containsKey(departmentKey)){

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

'{' 前应有空格。

) {
String departmentKey=user.getDepartment();
if (!userListByDepartment.containsKey(departmentKey)){
userListByDepartment.put(departmentKey,new ArrayList<>());

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

',' 后应有空格。

import java.util.Objects;

public class User {
public class User implements Comparable{

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

'{' 前应有空格。


@Override
public int compareTo(Object o) {
if (this.getAge()==((User) o).getAge()){

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

'==' 后应有空格。
'==' 前应有空格。
'{' 前应有空格。

if (this.getAge()==((User) o).getAge()){
return 0;
}
return (this.getAge()>((User) o).getAge())?1:-1;

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

'>' 后应有空格。
'>' 前应有空格。
'?' 后应有空格。
'?' 前应有空格。
':' 后应有空格。
':' 前应有空格。

@hcsp-bot

hcsp-bot commented Jun 4, 2022

Copy link
Copy Markdown
Contributor

你的提交 aa1c60b ,似乎失败了:Your tests failed on CircleCI

😅 请不要气馁,仔细分析原因,再接再厉!

1 similar comment
@hcsp-bot

hcsp-bot commented Jun 4, 2022

Copy link
Copy Markdown
Contributor

你的提交 aa1c60b ,似乎失败了:Your tests failed on CircleCI

😅 请不要气馁,仔细分析原因,再接再厉!

import java.util.Objects;

public class User {
public class User{

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

'{' 前应有空格。

@hcsp-bot

hcsp-bot commented Jun 4, 2022

Copy link
Copy Markdown
Contributor

你的提交 939ed00 ,似乎失败了:Your tests failed on CircleCI

😅 请不要气馁,仔细分析原因,再接再厉!

1 similar comment
@hcsp-bot

hcsp-bot commented Jun 4, 2022

Copy link
Copy Markdown
Contributor

你的提交 939ed00 ,似乎失败了:Your tests failed on CircleCI

😅 请不要气馁,仔细分析原因,再接再厉!

@hcsp-bot

hcsp-bot commented Jun 4, 2022

Copy link
Copy Markdown
Contributor

你的提交 7791049 ,似乎失败了:Your tests failed on CircleCI

😅 请不要气馁,仔细分析原因,再接再厉!

1 similar comment
@hcsp-bot

hcsp-bot commented Jun 4, 2022

Copy link
Copy Markdown
Contributor

你的提交 7791049 ,似乎失败了:Your tests failed on CircleCI

😅 请不要气馁,仔细分析原因,再接再厉!

}
userListByDepartment.get(departmentKey).add(user);
}
for (List<User> list:userListByDepartment.values()){

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

'{' 前应有空格。

@hcsp-bot

hcsp-bot commented Jun 4, 2022

Copy link
Copy Markdown
Contributor

你的提交 1876694 ,似乎失败了:Your tests failed on CircleCI

😅 请不要气馁,仔细分析原因,再接再厉!

1 similar comment
@hcsp-bot

hcsp-bot commented Jun 4, 2022

Copy link
Copy Markdown
Contributor

你的提交 1876694 ,似乎失败了:Your tests failed on CircleCI

😅 请不要气馁,仔细分析原因,再接再厉!

import java.util.Objects;

public class User {
public class User implements Comparable<User>{

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

'>' 后字符不合法。
'{' 前应有空格。

@hcsp-bot

hcsp-bot commented Jun 4, 2022

Copy link
Copy Markdown
Contributor

你的提交 2079a29 ,似乎失败了:Your tests failed on CircleCI

😅 请不要气馁,仔细分析原因,再接再厉!

1 similar comment
@hcsp-bot

hcsp-bot commented Jun 4, 2022

Copy link
Copy Markdown
Contributor

你的提交 2079a29 ,似乎失败了:Your tests failed on CircleCI

😅 请不要气馁,仔细分析原因,再接再厉!


@Override
public String toString() {
return "{" +

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

'+' 应另起一行。
用一个空格分隔非空白字符。

@hcsp-bot

hcsp-bot commented Jun 4, 2022

Copy link
Copy Markdown
Contributor

你的提交 1ac6949 ,似乎失败了:Your tests failed on CircleCI

😅 请不要气馁,仔细分析原因,再接再厉!

1 similar comment
@hcsp-bot

hcsp-bot commented Jun 4, 2022

Copy link
Copy Markdown
Contributor

你的提交 1ac6949 ,似乎失败了:Your tests failed on CircleCI

😅 请不要气馁,仔细分析原因,再接再厉!

public String toString() {
return "{" +
", name='" + name + '\'' +
", department='" + department + '\'' +", age=" + age +

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

'+' 后应有空格。
'+' 应另起一行。

@hcsp-bot

hcsp-bot commented Jun 4, 2022

Copy link
Copy Markdown
Contributor

你的提交 fa8051f ,似乎失败了:Your tests failed on CircleCI

😅 请不要气馁,仔细分析原因,再接再厉!

1 similar comment
@hcsp-bot

hcsp-bot commented Jun 4, 2022

Copy link
Copy Markdown
Contributor

你的提交 fa8051f ,似乎失败了:Your tests failed on CircleCI

😅 请不要气馁,仔细分析原因,再接再厉!

@Override
public String toString() {
return "{" +
"name='" + name + '\'' +

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

'+' 应另起一行。

@hcsp-bot

hcsp-bot commented Jun 4, 2022

Copy link
Copy Markdown
Contributor

你的提交 c5bac36 ,似乎失败了:Your tests failed on CircleCI

😅 请不要气馁,仔细分析原因,再接再厉!

1 similar comment
@hcsp-bot

hcsp-bot commented Jun 4, 2022

Copy link
Copy Markdown
Contributor

你的提交 c5bac36 ,似乎失败了:Your tests failed on CircleCI

😅 请不要气馁,仔细分析原因,再接再厉!

) {
String departmentKey=user.getDepartment();
List userList;
if (userListByDepartment.containsKey(departmentKey)){

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

'{' 前应有空格。

String departmentKey=user.getDepartment();
List userList;
if (userListByDepartment.containsKey(departmentKey)){
userList=userListByDepartment.get(departmentKey);

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

'=' 后应有空格。
'=' 前应有空格。

return u1.getAge() - u2.getAge();
}
});
userListByDepartment.put(departmentKey,userList);

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

',' 后应有空格。

@hcsp-bot

hcsp-bot commented Jun 4, 2022

Copy link
Copy Markdown
Contributor

你的提交 1992e24 ,似乎失败了:Your tests failed on CircleCI

😅 请不要气馁,仔细分析原因,再接再厉!

1 similar comment
@hcsp-bot

hcsp-bot commented Jun 4, 2022

Copy link
Copy Markdown
Contributor

你的提交 1992e24 ,似乎失败了:Your tests failed on CircleCI

😅 请不要气馁,仔细分析原因,再接再厉!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants