- String
- 字符串具有不可变的特性. 字符串被创建后会保存在常量池中. 每次新定义一个新的字符串或者修改一个字符串时, 并不是修改常量池中的值,而是在常量池中新创建一个字符串,将地址值给引用的变量.
- StringBufferd支持并发操作,线性安全的,适 合多线程中使用。StringBuilder不支持并发操作,线性不安全的,不适合多线程中使用。
- 无意识的递归
public class Demo {
@Override
public String toString() {
return "abc :" + this;
}
}
- String的格式化输出
- format方法. 可以打印,可以String.format对字符串进行格式化然后形成一个需要的字符串数据
- 参考链接: http://blog.csdn.net/lonely_fireworks/article/details/7962171/
public class FormatString {
public static void main(String[] args) {
int i = 10;
float y = 3.234f;
System.out.println("Row 1:["+i+" "+y+"]");
System.out.format("Row 1:[%d %f]", i,y);
}
}
- 关于正则匹配器的使用,如下
public static void main(String[] args) {
/**
* 正则匹配器,用于数据中检索目标数据
*/
String argus = "abcdbcabcegreabc";
String reg = "(abc)+";
Pattern compile = Pattern.compile(reg);
Matcher matcher = compile.matcher(argus);
while (matcher.find()) {
System.out.println("内容是:" +matcher.group());
System.out.println("开始index:"+matcher.start());
System.out.println("结束index:"+(matcher.end()-1));
}
}
参考链接: http:
- 代理模式
interface Interface {
void doSomeThing();
void doSomeThingElse();
}
class RealObject implements Interface{
public void doSomeThing() {
System.out.println("doSomeThing");
}
public void doSomeThingElse() {
System.out.println("doSomeThingElse");
}
}
class SimpleProxy implements Interface {
private Interface obj;
public SimpleProxy(Interface obj) {
this.obj = obj;
}
@Override
public void doSomeThing() {
System.out.println("新加的需求");
obj.doSomeThing();
}
@Override
public void doSomeThingElse() {
System.out.println("新加的需求");
obj.doSomeThingElse();
}
}
public class SimpleProxyDemo {
public static void consumer() {
Interface obj = new RealObject();
obj.doSomeThing();
obj.doSomeThingElse();
System.out.println("代理对象");
Interface proObj = new SimpleProxy(obj);
proObj.doSomeThing();
proObj.doSomeThingElse();
}
public static void main(String[] args) {
consumer();
}
}
- 动态代理
/**
* 动态代理处理程序
*/
public class SimpleDynamicProxy implements InvocationHandler{
private Object Object;
public SimpleDynamicProxy(java.lang.Object object) {
Object = object;
}
public Object invoke(Object proxy, Method method, Object[] args) throws Throwable {
System.out.println("动态代理执行--start:"+proxy.getClass().getSimpleName()+" 方法:"+method.getName()
+" 参数:"+args);
return method.invoke(Object, args);
}
}
/**
* 动态代理使用类
*/
public class SimpleDynamicUseClass {
public static void consumer(Interface obj) {
obj.doSomeThing();
obj.doSomeThingElse();
}
public static void main(String[] args) {
consumer(new RealObject());
System.out.println("----------------------");
Interface proxy = (Interface) Proxy.newProxyInstance(Interface.class.getClassLoader(),
RealObject.class.getInterfaces(), new SimpleDynamicProxy(new RealObject()));
consumer(proxy);
}
}
- 运行时类型信息相关 , 可参考链接 : http://blog.csdn.net/u013905744/article/details/52496611
- 空对象模式 , 可参考链接 : http://blog.csdn.net/xiaokang123456kao/article/details/69676798
- 泛型擦除 参考链接 : http://blog.csdn.net/lonelyroamer/article/details/7868820