IntelliJ IDEA中提供了一组叫做实时模板(live templates)的东西,类似于快捷键,可以实时自动生成自动代码模板,大大提高写代码的速度,其中最常用的当然是psvm和sout了。类似快捷键,你还可以自定义和修改实时模板,非常灵活。
这里列出IntelliJ IDEA默认的实时模板,简要介绍并给出用例。
public static void main(String[] args) {
}
System.out.println();
System.out.printf("");
System.out.println("helloworld.twoSum");
public static int[] twoSum(int[] nums, int target) {
//soutp →
System.out.println("nums = " + Arrays.toString(nums) + ", target = " + target);
int[] ints = new int[5];
//soutv →
System.out.println("ints = " + ints);
System.out::println
System.err.printf();
System.err::println
for (int i = 0; i < ; i++) {
}
for (:
) {
}
int[] ints = new int[5];
//iter →
for (int anInt : ints) {
}
int[] ints = new int[5];
//输入ints并选中,ctrl+alt+j或ctrl+alt+t,选择I →
for (int anInt : ints) {
}
int[] ints = new int[5];
//itar →
for (int i = 0; i < ints.length; i++) {
int anInt = ints[i];
}
int[] ints = new int[5];
//ritar →
for (int i = ints.length - 1; i >= 0; i--) {
int anInt = ints[i];
}
ArrayList<Integer> integers = new ArrayList<>();
//itco →
for (Iterator<Integer> iterator = integers.iterator(); iterator.hasNext(); ) {
Integer next = iterator.next();
}
ArrayList<Integer> integers = new ArrayList<>();
//itli →
for (int i = 0; i < integers.size(); i++) {
Integer integer = integers.get(i);
}
ArrayList<Integer> integers = new ArrayList<>();
Iterator<Integer> iterator = integers.iterator();
//itit →
while (iterator.hasNext()) {
Integer next = iterator.next();
}
Vector<String> dayNames = new Vector<>();
dayNames.add("Sunday");
dayNames.add("Monday");
dayNames.add("Tuesday");
Enumeration<String> days = dayNames.elements();
//iten →
while (days.hasMoreElements()) {
String s = days.nextElement();
}
String str = "a,b,c,d";
//ittok →
for (StringTokenizer stringTokenizer = new StringTokenizer(str); stringTokenizer.hasMoreTokens(); ) {
String s = stringTokenizer.nextToken();
}
String s = "";
//ifn →
if (s == null) {
}
String s = "";
//inn →
if (s != null) {
}
int[] ints = new int[5];
//inst →
if (ints instanceof Object) {
Object o = (Object) ints;
}
int[] ints = new int[5];
//lst →
ints[ints.length - 1]
int i = 5;
//mn →
i = Math.min(i, );
int i = 5;
//mx →
i = Math.max(i, );
private static final
public static final
public static final int
public static final String
String
ArrayList<Integer> integers = new ArrayList<>();
//toar →
integers.toArray(new Object[integers.size()])
public class MySingleton {
private static MySingleton instance = new MySingleton();
private MySingleton(){}
//geti →
public static MySingleton getInstance() {
return instance;
}
}
public class MySingleton {
private static MySingleton instance;
private MySingleton(){}
public static MySingleton getInstance() {
//lazy →
if (instance == null) {
instance = new MySingleton();
}
return instance;
}
}
throw new
ReentrantReadWriteLock reentrantReadWriteLock = new ReentrantReadWriteLock();
//输入//read data并选中,ctrl+alt+j或ctrl+alt+t,选择RL →
reentrantReadWriteLock.readLock().lock();
try {
//read data
} finally {
reentrantReadWriteLock.readLock().unlock();
}
ReentrantReadWriteLock reentrantReadWriteLock = new ReentrantReadWriteLock();
//输入// write data并选中,ctrl+alt+j或ctrl+alt+t,选择WL →
reentrantReadWriteLock.writeLock().lock();
try {
//write data
} finally {
reentrantReadWriteLock.writeLock().unlock();
}
for (int i = 0; i < s.length(); i++) {
}
for (int i = 100; i > 0; i--) {
}
for (String string : strings) {
}
String s1 = new String;
if (s == null) {
}
if (flag != null) {
}
!flag
if (flag) {
}
return s;