第3章 面向对象基础知识

来源:互联网 发布:3d打印机切片算法 编辑:程序博客网 时间:2024/06/03 17:42

String类的常用方法

public String(char[] value)public String(char[] value, int offset, int count)public char charAt(int index)public char[] toCharArray()public String(byte[] bytes)public String(byte[] bytes, int offset, int length)public byte[] getBytes()public byte[] getBytes(String charsetName)throws UnsupportedEncodingEceptionpublic boolean equals(String anObject)public boolean equalsIgnoreCase(String anotherString)public int compareTo(String anotherString)public boolean contains(String s)public int indexOf(String str)public int indexOf(String str, int fromIndex)public int lastIndexOf(String str)public int lastIndexOf(String str, int fromIndex)public boolean startsWith(String prefix)public boolean startsWith(String prefix, intoffset)public boolean endsWith(String suffix)public String replaceAll(String regex, String replacement)public String replaceFirst(String regex, String replacement)public String substring(int beginIndex) public String substring(int beginIndex, int endIndex)public String[] split(String regex)public String[] split(String regex, int limit)public String concat(Stirng str)public String toLowerCase()public String toUpperCase()public String trim()public int length()public String intern()public boolean isEmpty()

数据表一对多关系转为类间关系

一个部门Dept有多个雇员Emps

要根据部门取出雇员信息

class Dept {    private Emp[] emps ;    public void setEmp() {        this.emps = emps;    }    public Emp[] getEmps() {        return this.emps;    }}class Emp {}   public class Test {    System.out.println(dept.getInfo());    for(int x=0; x < dept.getEmps().length; x++) {        System.out.println(dept.getEmps()[x].getInfo());    }}
原创粉丝点击