时间:2021-05-02
在se中用惯了的StringTokenizer,在me中没有了,我还急着用,于是在Google上搜索了一下,果然有高手已经解决了,把代码放在下面:
import java.util.*;
public class StringTokenizer implements Enumeration { private void setMaxDelimChar() { if(delimiters == null) {maxDelimChar = '\0';return; } char c = '\0'; for(int i = 0; i < delimiters.length(); i ){ char c1 = delimiters.charAt(i); if(c < c1) c = c1; } maxDelimChar = c; }
public StringTokenizer(String s, String s1, boolean flag){ currentPosition = 0;newPosition = -1; delimsChanged = false;str = s; maxPosition = s.length(); delimiters = s1; retDelims = flag;setMaxDelimChar(); }
public StringTokenizer(String s, String s1) { this(s, s1, false); }
public StringTokenizer(String s) { this(s, " \t\n\r\f", false); }
private int skipDelimiters(int i) { if(delimiters == null) throw new NullPointerException();int j;for(j = i; !retDelims && j < maxPosition; j ) { char c = str.charAt(j); if(c > maxDelimChar || delimiters.indexOf(c) < 0) break; } return j; }
private int scanToken(int i){ int j; for(j = i; j < maxPosition; j ) { char c = str.charAt(j); if(c <= maxDelimChar && delimiters.indexOf(c) >= 0) break; } if(retDelims && i == j) { char c1 = str.charAt(j);if(c1 <= maxDelimChar && delimiters.indexOf(c1) >= 0) j ; }return j; }
public boolean hasMoreTokens(){ newPosition = skipDelimiters(currentPosition); return newPosition < maxPosition; }
public String nextToken() { currentPosition = newPosition < 0 || delimsChanged ? skipDelimiters(currentPosition) : newPosition; delimsChanged = false; newPosition = -1; if(currentPosition >= maxPosition) { throw new NoSuchElementException(); } else{ int i = currentPosition; currentPosition = scanToken(currentPosition); return str.substring(i, currentPosition); } }
public String nextToken(String s){ delimiters = s; delimsChanged = true;setMaxDelimChar();return nextToken(); }
public boolean hasMoreElements() { return hasMoreTokens(); }
public Object nextElement() { return nextToken(); }
public int countTokens() { int i = 0; for(int j = currentPosition; j < maxPosition;) { j = skipDelimiters(j); if(j >= maxPosition) break;j = scanToken(j); i ; } return i; }
private int currentPosition; private int newPosition; private int maxPosition; private String str; private String delimiters; private boolean retDelims; private boolean delimsChanged; private char maxDelimChar;
}
本文源自:翔宇亭——IT乐园(http://),转载请保留此信息!声明:本页内容来源网络,仅供用户参考;我单位不保证亦不表示资料全面及准确无误,也不保证亦不表示这些资料为最新信息,如因任何原因,本网内容或者用户因倚赖本网内容造成任何损失或损害,我单位将不会负任何法律责任。如涉及版权问题,请提交至online#300.cn邮箱联系删除。
Android游戏开发中主要的类除了控制类就是显示类,比较重要也很复杂的就是显示和游戏逻辑的处理。在J2ME中可以通过Display和Canvas来实现显示,而
JDK,J2EE,J2SE,J2ME的概念区别是什么呢?1.这些是什么?JDK是Javadevelopmenttoolkit,相当于是Java的库函数,是编译,
Java2MicroEdition(J2ME)是建立在一个由profiles,配置,虚拟机和主持操作系统等部分所组成的标准架构之上的。这些内容组成了完整的J
我们都知道,JavaME以往称作J2ME(JavaPlatform,MicroEdition),是为机顶盒、移动电话和PDA之类嵌入式消费电子设备提供的Java
Android的Bitmap和J2ME的Image比较类似。 如果我想从resource里读入一个图片,然后在这个图片上draw一点自己的信息,比如文字。