写for循环快捷生成方式
1.普通for循环
快捷键方式:len
.fori
+回车键
(其中len为循环长度)
例如:编写10次循环
java
10.fori+回车键
得到的效果:
java
for (int i = 0; i < 10; i++) {
}
2.增强for循环
快捷键方式:arr
.for
+回车键
(其中arr为需要遍历的数组或者对象名称)
例如:创建了一个Person类型(自定义对象类型)的ArrayList集合叫list,对list进行遍历
java
list.for+回车键
效果:
java
for (Person person : list) {
}
idea中各种for循环的快捷键
使用Intellij idea 时,想要快捷生成for循环代码块
itar 生成array for代码块
java
for (int i = 0; i < array.length; i++) {
= array[i];
}
itco 生成Collection迭代
java
for (Iterator iterator = collection.iterator(); iterator.hasNext(); ) {
Object next = iterator.next();
}
iten 生成enumeration遍历
java
while (enumeration.hasMoreElements()) {
Object nextElement = enumeration.nextElement();
}
iter 生成增强for循环
java
for (String arg : args) {
}
itit 生成iterator 迭代
java
while (iterator.hasNext()) {
Object next = iterator.next();
}
itli 生成List的遍历
java
for (int i = 0; i < list.size(); i++) {
Object o = list.get(i);
}
ittok 生成String token遍历
java
for (StringTokenizer stringTokenizer = new StringTokenizer(); stringTokenizer.hasMoreTokens(); ) {
String s = stringTokenizer.nextToken();
}
itve 生成Vector数组迭代
java
for (int i = 0; i < vector.size(); i++) {
Object elementAt = vector.elementAt(i);
}
另外两个和循环无关,只是方便创建
itaws 生成Axis2 web service调用
java
try {
MyServiceStub stub = new MyServiceStub();
stub.sayHelloWorldFrom();
} catch (Exception ex) {
ex.printStackTrace();
}
itws 生成 Axis web service调用
java
try {
MyServiceLocator locator = new MyServiceLocator();
Activator service = locator.get();
// If authorization is required
//((MyService_Soap_BindingStub)service).setUsername("user3");
//((MyService_Soap_BindingStub)service).setPassword("pass3");
// invoke business method
service.businessMethod();
} catch (javax.xml.rpc.ServiceException ex) {
ex.printStackTrace();
} catch (java.rmi.RemoteException ex) {
ex.printStackTrace();
}