今天星期天,参加培训的第二十四天,早起却没有第一个到教室,因为钥匙不在我手里,然后正常看书什么的,然后老师上课讲了一个知识点:因为“-”在正则表达式里有特殊含义:所以用法如下:
String[] number = Allnumber.split("[+/*\\-]");
然后就是在看书忘记老师有讲什么东西了,一个知识点如下:
package am;
public abstract class MyArrayList {
protected int size=0;
protected MyArrayList() {
}
protected MyArrayList(Object[] objects) {
for(int i=0;i<objects.length;i++) {
add(objects[i]);
}
}
public void add(Object e) {
add(size,e);
}
abstract public void add(int i,Object e) ;
}
package am;
import java.util.Arrays;
public class MyArrayLindedList extends MyArrayList{
private Object[] data = new Object[5];
private int num = 1;
public MyArrayLindedList(Object[] o) {
// TODO Auto-generated constructor stub
super(o);//不能用因为用父类不能初始化子类对象,data是null;
// for(int i=0;i<o.length;i++) {
// add(o[i]);
// }
// data = o;
// size = o.length;
}
@Override
public void add(int index, Object e) {
// TODO Auto-generated method stub
int num1 = num;
System.out.println(num1);
ensureCapacity();
for(int i = size-1;i>=index;i--) {
data[i+1]=data[i];
}
data[index]=e;
size++;
}
private void ensureCapacity() {
System.out.println(data.length);
if(size>=data.length) {
Object[] newData = new Object[size*2+1];
System.arraycopy(data, 0, newData, 0, size);
data = newData;
}
}
public String toString() {
return Arrays.toString(data);
}
public static void main(String[] args) {
Object[] o = {1,2,3,4,5,6};
MyArrayLindedList m = new MyArrayLindedList(o);
m.add(4);
System.out.println(m.toString());
}
}
然后就是实现先进先出,后进先出的集合:
package am;
import java.util.ArrayList;
public class GenericStack <E> {
private ArrayList<E> list = new ArrayList<E>();
public int getSize() {
return list.size();
}
public E peek() {
return list.get(getSize()-1);
}
public void push(E o) {
list.add(o);
}
public E pop() {
E o = list.get(getSize()-1);
list.remove(getSize()-1);
return o;
}
public boolean isEmpty() {
return list.isEmpty();
}
}
用它来完成了计算器,
<span style="font-size:14px;">import java.util.Vector;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JScrollPane;
import javax.swing.JTable;
import javax.swing.table.DefaultTableCellRenderer;
import javax.swing.table.DefaultTableModel;
public class TableTest extends JFrame{
private JTable table;
private DefaultTableModel defaultTableModel = null;
private JScrollPane scrollPane;
String Names[] = {"姓名", "性别","年龄"};
Object[] object=new Object[5];
private String ss[][];
public TableTest() {
setTitle("表格测试");
setSize(500, 300);
setLocation(500, 200);
scrollPane = new JScrollPane();
scrollPane.setSize(300, 200);
//创建一个只有表头的表格模型
defaultTableModel = new DefaultTableModel( null,Names);
defaultTableModel.addRow(object);
table = new JTable(defaultTableModel);
//设置单元格中的文字居中 非表头单元格
DefaultTableCellRenderer r = new DefaultTableCellRenderer();
r.setHorizontalAlignment(JLabel.CENTER);
table.setDefaultRenderer(Object.class, r);
scrollPane.setViewportView(table);
add(scrollPane);
setDefaultCloseOperation(DISPOSE_ON_CLOSE);
setVisible(true);
/* //获取表格中的信息
*
* Vector data = defaultTableModel.getDataVector();
* VectorToString(data);
*
*/
}
//将二维矢量数组转化成二维字符串数组 存储在数组ss中
public void VectorToString(Vector data){
Vector rowData;
ss = new String[10][3];
String field="";
for(int i = 0; i<data.size();i++){
rowData =(Vector) data.get(i);
for(int j=0;j<rowData.size();j++){
field = (String) rowData.get(j);
ss[i][j] = field;
}
}
}
public static void main(String[] args) {
new TableTest();
}
}</span>
行了就这样吧,别的没有什么好说的了,回去睡觉了。