Java by API/java.text/CharacterIterator — различия между версиями
Admin (обсуждение | вклад) м (1 версия) |
|
(нет различий)
|
Версия 17:43, 31 мая 2010
Содержание
CharacterIterator: current()
import java.text.CharacterIterator;
import java.text.StringCharacterIterator;
public class Main {
public static void main(String[] argv) throws Exception {
CharacterIterator it = new StringCharacterIterator("abcd");
char ch = it.first();
ch = it.current();
ch = it.next();
ch = it.current();
ch = it.last();
int pos = it.getIndex();
ch = it.next();
pos = it.getIndex();
ch = it.previous();
ch = it.setIndex(1);
}
}
CharacterIterator.DONE
import java.text.CharacterIterator;
import java.text.StringCharacterIterator;
public class Main {
private static final String text = "this is a test";
public static void main(String[] args) {
CharacterIterator it = new StringCharacterIterator(text);
for (char ch = it.last(); ch != CharacterIterator.DONE; ch = it.previous()) {
System.out.print(ch);
}
}
}
CharacterIterator: first()
import java.text.CharacterIterator;
import java.text.StringCharacterIterator;
public class Main {
public static void main(String[] argv) throws Exception {
CharacterIterator it = new StringCharacterIterator("abcd");
char ch = it.first();
ch = it.current();
ch = it.next();
ch = it.current();
ch = it.last();
int pos = it.getIndex();
ch = it.next();
pos = it.getIndex();
ch = it.previous();
ch = it.setIndex(1);
}
}
CharacterIterator: getIndex()
import java.text.CharacterIterator;
import java.text.StringCharacterIterator;
public class Main {
public static void main(String[] argv) throws Exception {
CharacterIterator it = new StringCharacterIterator("abcd");
char ch = it.first();
ch = it.current();
ch = it.next();
ch = it.current();
ch = it.last();
int pos = it.getIndex();
ch = it.next();
pos = it.getIndex();
ch = it.previous();
ch = it.setIndex(1);
}
}
CharacterIterator: last()
import java.text.CharacterIterator;
import java.text.StringCharacterIterator;
public class Main {
private static final String text = "this is a test";
public static void main(String[] args) {
CharacterIterator it = new StringCharacterIterator(text);
for (char ch = it.last(); ch != CharacterIterator.DONE; ch = it.previous()) {
System.out.print(ch);
}
}
}
CharacterIterator: previous()
import java.text.CharacterIterator;
import java.text.StringCharacterIterator;
public class Main {
private static final String text = "this is a test";
public static void main(String[] args) {
CharacterIterator it = new StringCharacterIterator(text);
for (char ch = it.last(); ch != CharacterIterator.DONE; ch = it.previous()) {
System.out.print(ch);
}
}
}
CharacterIterator: setIndex(int position)
import java.text.CharacterIterator;
import java.text.StringCharacterIterator;
public class Main {
public static void main(String[] argv) throws Exception {
CharacterIterator it = new StringCharacterIterator("abcd");
char ch = it.first();
ch = it.current();
ch = it.next();
ch = it.current();
ch = it.last();
int pos = it.getIndex();
ch = it.next();
pos = it.getIndex();
ch = it.previous();
ch = it.setIndex(1);
}
}