package heima;
import java.util.ArrayList;
import java.util.List;
import java.util.ListIterator;
public class kkk {
public static void main(String[] args) {
List<String> list = new ArrayList<>();
list.add("hello");
list.add("world");
list.add("java");
ListIterator<String>lit=list.listIterator();
while(lit.hasNext()){
String s= lit.next();
System.out.println(s);
}
}
}
package heima;
import java.util.ArrayList;
import java.util.List;
import java.util.ListIterator;
public class kkk {
public static void main(String[] args) {
List<String> list = new ArrayList<>();
list.add("hello");
list.add("world");
list.add("java");
// ListIterator lit = list.listIterator();
// while (lit.hasNext()) {
// String s = lit.next();
// System.out.println(s);
// }
// System.out.println("------------");
// while(lit.hasPrevious()){
// String s= lit.previous();
// System.out.println(s);
// }
ListIteratorlit= list.listIterator();
while(lit.hasNext()){
String s=lit.next();
if(s.equals("world")){
lit.add("javaee");
}
}
System.out.println(list);
}
}
package heima;
import java.util.ArrayList;
import java.util.List;
public class kkk {
public static void main(String[] args) {
int[] arr={1,2,3,4,5};
for(int i: arr){
System.out.println(i);
}
System.out.println("--------");
String[] strArray={"hello","world","java"};
for(String s:strArray){
System.out.println(s);
}
System.out.println("-----------");
List<String>list=new ArrayList<String>();
list.add("hello");
list.add("world");
list.add("java");
for(String s: list){
System.out.println(s);
}
System.out.println("---------");
for(String s:list){
if(s.equals("world")){
list.add("javaee");
}
}
}
}
//1
// 2
// 3
// 4
// 5
// --------
// hello
// world
// java
// -----------
// hello
// world
// java
// ---------
// Exception in thread "main" java.util.ConcurrentModificationException
// at java.util.ArrayList$Itr.checkForComodification(ArrayList.java:911)
// at java.util.ArrayList$Itr.next(ArrayList.java:861)
// at heima.kkk.main(kkk.java:26)
//
// 进程已结束,退出代码为 1
package heima;
public class Student {
private String name;
private int age;
public Student(String name, int age) {
this.name = name;
this.age = age;
}
public Student(String name) {
this.name = name;
}
public Student(int age) {
this.age = age;
}
public Student() {
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public int getAge() {
return age;
}
public void setAge(int age) {
this.age = age;
}
}
package heima;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
public class ListDemo {
public static void main(String[] args) {
List<Student>list=new ArrayList<>();
Student s1=new Student("ddwe",55);
Student s2=new Student("dd",52);
Student s3=new Student("add",77);
list.add(s1);
list.add(s2);
list.add(s3);
Iterator<Student>it=list.iterator();
while(it.hasNext()){
Student s= it.next();
System.out.println(s.getName()+s.getAge());
}
for(int i=0;i< list.size();i++){
Student s=list.get(i);
System.out.println(s.getName()+s.getAge());
}
for(Student s:list){
System.out.println(s.getName()+s.getAge());
}
}
}