review
20190701
Interface supplement
A, java is to achieve more than single inheritance
- Single inheritance:
A class can have only one parent
public class D extends D1 {
}
2. Multi-realization
- A class can implement multiple interfaces simultaneously
- When a class implements multiple interfaces, which need to implement all the abstract methods declared in the interface of these
public interface A {
void fun1();
}
public interface B {
void fun2();
}
public class AAA implements A,B{
@Override
public void fun1() {
}
@Override
public void fun2() {
}
}
}
-
- public interface A{
void fun1();
}
public interface B extends A{ //接口B继承自接口A
void fun2();
}
public class AB implements B{
@Override
public void fun1() {
}
@Override
public void fun2() {
}
}
}
- public interface A{
Set (key, about 50%) 4. java in
5. Collection
A so-called order-disorder means: if the order of the elements in the order taken into identical, orderly, that is inconsistent disordered
List: list where it is ordered elements, elements allow repeat
ArrayList: variable length arrays
Example:
public static void main(String[] args) {
List list = new ArrayList)_;
list.add("aa");
list.add(123);
list.add(true);
list.add(new Date());
list.add(124);
list.add(3.14);
System.out.println(list.get(0) + " .... " + list.get(3));
System.out.println(list.size());
System.out.println(list);
System.out.println(list.toString());
for (Object obj : list) {
System.out.println(obj);
}
list.remove(0);//根据下标移除
list.clear();
System.out.println(list.size());
}
}
6. Generics
public static void main(String[] args) {
List<String> list = new ArrayList<>();
list.add("1234");
list.add("true");
list.add("aaaa");
list.add("bbbb");
list.add("cccc"); String e3 = list.get(3); System.out.println(e3); int size = list.size(); System.out.println(size); for (String item : list) { System.out.println(item); } System.out.println("---------------------"); //Iterator迭代器 Iterator<String> iterator = list.iterator(); while (iterator.hasNext()) {//判断是否还有下一个元素,有的话返回true String next = iterator.next();// remove the element, while the pointer to the current position } System.out.println (Next);
}
}