IDEA (2) -MAC code template
IDEA provides many of the code that comes with templates, these templates are mainly used for the development of the code we often made into a template, such as the for loop, this is often used code, if no code template, we need a one manual enter, with code template also just enter the shortcut for the template, it will automatically generate the code for the relevant cycle, improve development efficiency.
First, the code template comes
Location Preferences
-> Editor
->Live Templetes
java development land there are four main groups iterations
, other
, output
,plain
1、iterations
The group associated with traversal, introduce common templates
1、iter # for增强循环
2、itli # list集合遍历 正序
3、itar # 数组正序遍历
4、aitar # 数组倒序遍历
示例
List<String> str = new ArrayList();
//1、 iter 模版
for (String s : str) {
}
//2、itli 模版
for (int i = 0; i < str.size(); i++) {
String s = str.get(i);
}
//将集合转为数组
String[] arr =(String[])str.toArray();
//3、itar 数组正序输出
for (int i = 0; i < arr.length; i++) {
String s = arr[i];
}
//4、ritar 数组倒叙输出
for (int i = arr.length - 1; i >= 0; i--) {
String s = arr[i];
}
2、other
Common templates
1、ifn #判断当前对象是否等于null
2、inn #判断当前对象是否不等于null
3、lazy #判断当前对象是否等于null,如果等于null新建一个对象(lazy懒加载的意思)
4、toar #集合转数组
5、psvm #main方法 这个不能在某个方法内使用,要在方法外
示例
String str = null;
//1、ifn 模版
if (str == null) {
}
//2、inn 模版
if (str != null) {
}
//3、lazy 模版
if (str == null) {
str = new String();
}
List<String> stringList = new ArrayList();
//4、toar 模版
stringList.toArray(new Object[stringList.size()]);
//5 psvm 模版
public static void main(String[] args) {
}
3、output
Output-related templates, common template
1、serr #错误输出
2、sout #输出
3、souf #输出空字符串
4、soutv #输出当前对象
5、soutp #System.out.println("方法形参名 = " + 形参名);
示例
//1、serr 错误输出
System.err.println();
//2、sout 正常输出
System.out.println();
//3、soutf 输出空字符串
System.out.printf("");
//4、soutv 输出当前对象
String st = "小小";
System.out.println("st = " + st);
4、plain
Common templates
1、prsf # private static final
2、psf # public static final
3、psfi # public static final int
4、psfs # public static final String
5、thr # throw new
Second, the custom templates
The above are some of the IDEA comes with templates, but the actual development process, the need to customize your own code templates, so here start customizing your own code templates.
1. Create group
Custom templates a good idea to create a group, their own custom templates are placed in this group.
Editor->Live Templates
Click the + sign to add a template of their own group.
This group has been created.
2. Create a template
When the fourth step 4 Here is a range of applications, the emergence of the above tips, you need to click define settings, then click define, select java, indicating that the template for java file, then click ok.
Enter the test template has been out shows a success.
只要自己变优秀了,其他的事情才会跟着好起来(少将17)