JavaME est assez peu répandu sur les fonctionnalités. Veuillez lister vos fonctions utilitaires préférées pour en faire l'utilisation plus comme Java, un par réponse. Essayez de rendre vos réponses spécifiques à Java ME.Java ME Utility Functions
2
A
Répondre
0
découpant une chaîne
static public String[] split(String str, char c)
{
int l=str.length();
int count = 0;
for(int i = 0;i < l;i++)
{
if (str.charAt(i) == c)
{
count ++;
}
}
int first = 0;
int last = 0;
int segment=0;
String[] array = new String[count + 1];
for(int i=0;i<l;i++)
{
if (str.charAt(i) == c)
{
last = i;
array[segment++] = str.substring(first,last);
first = last;
}
if(i==l-1){
array[segment++] = str.substring(first,l);
}
}
return array;
}
0
Lecture d'une ligne d'un lecteur. Voir aussi this question.
public class LineReader{
private Reader in;
private int bucket=-1;
public LineReader(Reader in){
this.in=in;
}
public boolean hasLine() throws IOException{
if(bucket!=-1)return true;
bucket=in.read();
return bucket!=-1;
}
//Read a line, removing any /r and /n. Buffers the string
public String readLine() throws IOException{
int tmp;
StringBuffer out=new StringBuffer();
//Read in data
while(true){
//Check the bucket first. If empty read from the input stream
if(bucket!=-1){
tmp=bucket;
bucket=-1;
}else{
tmp=in.read();
if(tmp==-1)break;
}
//If new line, then discard it. If we get a \r, we need to look ahead so can use bucket
if(tmp=='\r'){
int nextChar=in.read();
if(tmp!='\n')bucket=nextChar;//Ignores \r\n, but not \r\r
break;
}else if(tmp=='\n'){
break;
}else{
//Otherwise just append the character
out.append((char) tmp);
}
}
return out.toString();
}
}
1
Cadre Petit Logging
Questions connexes
- 1. Rabin Hash Functions - Implémentation FAST en Java
- 2. Importation de clojure.contrib.generic.math-functions
- 3. LLVM extern functions
- 4. Namespace Class Functions
- 5. YUI Event Utility problème
- 6. Enumeration Utility Library
- 7. Comment lancer com.apple.tools.info-plist-utility?
- 8. Animation en Java ME
- 9. pauseApp Java ME
- 10. java me textfield
- 11. Menus contextuels - Java ME
- 12. Java ME mémoire insuffisante
- 13. Javascript Member Functions Out of Scope
- 14. Communication Java ME et Java EE
- 15. Emplacement javadoc dans Java ME?
- 16. Où s'installe Java JAR ME?
- 17. Remplacement Class.getSuperclass() sur Java ME?
- 18. Java ME dessine un rectangle
- 19. Google maps Commandes de géométrie GMaps Utility Library
- 20. iPhone OS Utility App - Vue Flipside et communication Main View
- 21. Comment utiliser .dll en Java ME
- 22. Java ME options de l'émulateur SDK
- 23. Java ME obtenir la date d'hier
- 24. Java ME 3.0 SDK sous Linux?
- 25. Lire les lignes dans Java ME
- 26. Plusieurs alertes consécutives en Java ME
- 27. Java KeyListener me donne "Inconnu codeTouche: 0x0"
- 28. Comment envoyer une image dans Java ME?
- 29. Couche de compatibilité Java ME pour Android
- 30. Chaîne remplacer en Java ME double espace
Voir aussi: [cette question] (http://stackoverflow.com/questions/3340954/java-me-utility-functions/3524999# 3524999) – Casebash