如何高效运用idea模板进行编程知识梳理?

2026-05-21 07:533阅读0评论SEO资源
  • 内容介绍
  • 文章标签
  • 相关推荐

本文共计982个文字,预计阅读时间需要4分钟。

如何高效运用idea模板进行编程知识梳理?

模板编程是强大的功能,它提高了开发人员的编程效率。例如,编写main函数:public static void main(String[] args) { } 在常规情况下,我们需要逐个输入每个字符,但这种方式太慢了,有模板就方便多了。

模板编程是idea的强大功能,也提高了开发人员的编程效率,比如输入main函数:

public static void main(String[] args){ }

正常情况下我们需要每个字母挨个输入,但是这样输入太慢了,有了模板编程,我们只需要输入psvm或者main,然后回车,就会输出

public static void main(String[] args){ }

,是不是大大的提高了编码速度。这里对模板编程进行简单的介绍。

一、模板编程简介

模板编程的位置如下图:File-->settings-->Editor

其中,Editor-->General-->Postfix Completion 和Editor-->Live Templates下面都有模板编程的配置,不同的是Live Templates下的模板是可以新建和修改的

java编程常用的模板我在上图中标注出来了

二、常用模板

先介绍一下常用的、idea自带的模板

1.static final 变量

prsf:private static final

psf:public static final

psfi:public static final int

如何高效运用idea模板进行编程知识梳理?

psfs: public static final String

2. main函数

psvm/main: public static void main(String[] args) { }

3. for循环

fori: for (int i = 0; i < ; i++) { } iter: for (String arg : args) { } itar: for (int i = 0; i < args.length; i++) { String arg = args[i]; }

4. list循环

List<String> stringList = new ArrayList<>();

stringList.fori: for (int i = 0; i < stringList.size(); i++) { }

stringList.for: for (String s : stringList) { }

stringList.forr: for (int i = stringList.size() - 1; i >= 0; i--) { }

5. 其他

假设有这样的对象

Producer producer = new Producer();

则对象判空:

ifn: if (producer == null) { } inn: if (producer != null) { } // xxx.nn producer.nn: if (producer != null) { } // xxx.null producer.null: if (producer == null) { }

sout:System.out.println();

idea常用模板编程效果:

模板编程: public class TemplateTest { // prsf private static final int a=10; //psf public static final int b=10; //psfi public static final int c=1000; // psfs public static final String d="qqq"; // psvm public static void main(String[] args) { System.out.println("hello"); // soutm System.out.println("TemplateTest.main"); // soutv int n=10; System.out.println("n = " + n); // xxx.sout int num=100; System.out.println(num); // souf System.out.printf(""); // for循环 //fori for (int i = 0; i <100 ; i++) { // i.sout System.out.println(i); //i.soutv System.out.println("i = " + i); // i.switch switch (i) { } } // iter for (String arg : args) { } // itar for (int i = 0; i < args.length; i++) { String arg = args[i]; } List<String> stringList = new ArrayList<>(); // stringList.fori for (int i = 0; i < stringList.size(); i++) { } // stringList.for for (String s : stringList) { } // stringList.forr for (int i = stringList.size() - 1; i >= 0; i--) { } Producer producer = new Producer(); // ifn if (producer == null) { } // inn if (producer != null) { } // xxx.nn if (producer != null) { } // xxx.null if (producer == null) { } // inst if (producer instanceof Object) { Object o = (Object) producer; } } }

我们可以通过快捷键 ctrl+j 来查看模板编程提示:

更多的idea编程模板可以去Live Templates下面查看

三、模板自定义与修改

我们可以在Live Templates 位置下自改和自定义模板

1. 修改

比如对psfi进行修改

修改前:

psfi:public static final int

修改后:

psfi:public static final int i =

2. 自定义模板

可以通过选择右边的+自定义模板,步骤如下:

模板里面的$var$是生成时光标停留的位置

点击define,选择应用范围(没有此步骤,模板不生效),这里选择Java,则勾选Java

自定义效果:

// test public void test(){ }

总结

到此这篇关于idea 模板编程的文章就介绍到这了,更多相关idea 模板编程内容请搜索易盾网络以前的文章或继续浏览下面的相关文章希望大家以后多多支持易盾网络!

本文共计982个文字,预计阅读时间需要4分钟。

如何高效运用idea模板进行编程知识梳理?

模板编程是强大的功能,它提高了开发人员的编程效率。例如,编写main函数:public static void main(String[] args) { } 在常规情况下,我们需要逐个输入每个字符,但这种方式太慢了,有模板就方便多了。

模板编程是idea的强大功能,也提高了开发人员的编程效率,比如输入main函数:

public static void main(String[] args){ }

正常情况下我们需要每个字母挨个输入,但是这样输入太慢了,有了模板编程,我们只需要输入psvm或者main,然后回车,就会输出

public static void main(String[] args){ }

,是不是大大的提高了编码速度。这里对模板编程进行简单的介绍。

一、模板编程简介

模板编程的位置如下图:File-->settings-->Editor

其中,Editor-->General-->Postfix Completion 和Editor-->Live Templates下面都有模板编程的配置,不同的是Live Templates下的模板是可以新建和修改的

java编程常用的模板我在上图中标注出来了

二、常用模板

先介绍一下常用的、idea自带的模板

1.static final 变量

prsf:private static final

psf:public static final

psfi:public static final int

如何高效运用idea模板进行编程知识梳理?

psfs: public static final String

2. main函数

psvm/main: public static void main(String[] args) { }

3. for循环

fori: for (int i = 0; i < ; i++) { } iter: for (String arg : args) { } itar: for (int i = 0; i < args.length; i++) { String arg = args[i]; }

4. list循环

List<String> stringList = new ArrayList<>();

stringList.fori: for (int i = 0; i < stringList.size(); i++) { }

stringList.for: for (String s : stringList) { }

stringList.forr: for (int i = stringList.size() - 1; i >= 0; i--) { }

5. 其他

假设有这样的对象

Producer producer = new Producer();

则对象判空:

ifn: if (producer == null) { } inn: if (producer != null) { } // xxx.nn producer.nn: if (producer != null) { } // xxx.null producer.null: if (producer == null) { }

sout:System.out.println();

idea常用模板编程效果:

模板编程: public class TemplateTest { // prsf private static final int a=10; //psf public static final int b=10; //psfi public static final int c=1000; // psfs public static final String d="qqq"; // psvm public static void main(String[] args) { System.out.println("hello"); // soutm System.out.println("TemplateTest.main"); // soutv int n=10; System.out.println("n = " + n); // xxx.sout int num=100; System.out.println(num); // souf System.out.printf(""); // for循环 //fori for (int i = 0; i <100 ; i++) { // i.sout System.out.println(i); //i.soutv System.out.println("i = " + i); // i.switch switch (i) { } } // iter for (String arg : args) { } // itar for (int i = 0; i < args.length; i++) { String arg = args[i]; } List<String> stringList = new ArrayList<>(); // stringList.fori for (int i = 0; i < stringList.size(); i++) { } // stringList.for for (String s : stringList) { } // stringList.forr for (int i = stringList.size() - 1; i >= 0; i--) { } Producer producer = new Producer(); // ifn if (producer == null) { } // inn if (producer != null) { } // xxx.nn if (producer != null) { } // xxx.null if (producer == null) { } // inst if (producer instanceof Object) { Object o = (Object) producer; } } }

我们可以通过快捷键 ctrl+j 来查看模板编程提示:

更多的idea编程模板可以去Live Templates下面查看

三、模板自定义与修改

我们可以在Live Templates 位置下自改和自定义模板

1. 修改

比如对psfi进行修改

修改前:

psfi:public static final int

修改后:

psfi:public static final int i =

2. 自定义模板

可以通过选择右边的+自定义模板,步骤如下:

模板里面的$var$是生成时光标停留的位置

点击define,选择应用范围(没有此步骤,模板不生效),这里选择Java,则勾选Java

自定义效果:

// test public void test(){ }

总结

到此这篇关于idea 模板编程的文章就介绍到这了,更多相关idea 模板编程内容请搜索易盾网络以前的文章或继续浏览下面的相关文章希望大家以后多多支持易盾网络!