截取字符串(中英混合串) JAVA代码
public class SplitString {
/**
* @param args
*/
public static void main(String[] args) {
String str = "中Zell中国5000年,Congruations!";
int bytes = 8;
str = new SplitString().getSubString(str, bytes);
System.out.println(str);
}
public String getSubString(String str,int bytes){
int temp = bytes;
byte [] AllBytes = str.getBytes();
int AllStrByteLen = AllBytes.length;
if(bytes > AllStrByteLen | bytes <= 0){
return str;
}
int ChinaWordsNum = 0;
for(int i=0;i<temp;i++){
int IntOfByte = (int)AllBytes[i];
if(IntOfByte < 0 ){
ChinaWordsNum+=1;
}
}
if(ChinaWordsNum%2 == 0){
return new String(AllBytes,0,temp);
}else{
if(bytes == 1){
return null;
}
&
相关文档:
第1条 How to Write an Equality Method in Java
http://www.artima.com/lejava/articles/equality.html
How to Write an Equality Method in Java
by Martin Odersky, Lex Spoon, and Bill Venners
June 1, 2009
Summary
This article describes a technique for overriding the equals method t ......
一、向上转型。
通俗地讲即是将子类对象转为父类对象。此处父类对象可以是接口。
1,向上转型中的方法调用。
看下面代码:
package com.wensefu.others;
public class Animal {
public void eat(){
System.out.println("animal eatting...");
}
}
class Bird extends Animal{
public void ......
1.
BufferedReader in = new BufferedReader(new FileReader("远程文件"));
in.readLine() ;
l 使用 Java 操作文本文件的方法详解
http://java.ccidnet.com/art/3737/20041108/523627_1.html
l FileReader 是什么类?和 FileInputStream 有什么不同???
ht ......
1.什么是序列化
对象的寿命通常随着生成该对象的程序的终止而终止。有时候,可 能需要 将 对象的状态保存下来,在需要时再将对象恢复。我们把对象的这种能记录自己的状态以便将来再生的能力 。叫作对象的持续性(persistence)。对象通过写出描述自己状态的数值来记录自己 ,这个过程叫对象的序列化(Serialization) 。序列化 ......
关于volatile
我们知道,在Java中设置变量值的操作,除了long和double类型的变量外都是原子操作,也就是说,对于变量值的简单读写操作没有必要进行同步。
这在JVM 1.2之前,Java的内存模型实现总是从主存读取变量,是不需要进行特别的注意的。而随着JVM的成熟和优化,现在在多线程环境下
volatile关键字的使用变得非常重 ......