Java by API/java.text/CharacterIterator

Материал из Java эксперт
Версия от 14:44, 31 мая 2010; Admin (обсуждение | вклад) (1 версия)
(разн.) ← Предыдущая | Текущая версия (разн.) | Следующая → (разн.)
Перейти к: навигация, поиск

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);
  }
}