Order of import statements in java [closed]

2019-03-12 21:49发布

Just to know. Which is the proper way of ordering import statements? Also which has more readability?

like,

  • External classes (like java.util.List) and then internal package
    classes.
  • Just in alphabetical order

Thanks in advance.

8条回答
祖国的老花朵
2楼-- · 2019-03-12 22:14

I prefer this :

1) First group imports based on external and internal APIs 2)Alphabetically within each group

查看更多
劫难
3楼-- · 2019-03-12 22:19

Im not sure if there is a standard. But some projects such like android use the following rule.

  1. First import project specific files (android)
  2. Second comes the third party files and library.
  3. The java standard api files.

Each group is seperated by an extra line. And each group has their imports in alphabetical order.

AFAIK these are based on our preference.

查看更多
登录 后发表回答