List of usage examples for java.lang String charAt
public char charAt(int index)
From source file:MainClass.java
License:asdf
public static void main(String[] argv) throws Exception { CharBuffer buffer = CharBuffer.allocate(100); String string = "asdf"; for (int i = 0; i < string.length(); i++) { buffer.put(string.charAt(i)); }//from ww w.j a v a 2 s . c om buffer.flip(); drainBuffer(buffer); buffer.clear(); }
From source file:Main.java
public static void main(String args[]) throws IOException { ByteArrayOutputStream outStream = new ByteArrayOutputStream(); String s = "This is a test."; for (int i = 0; i < s.length(); ++i) outStream.write(s.charAt(i)); System.out.println("outstream: " + outStream); System.out.println("size: " + outStream.size()); ByteArrayInputStream inStream = new ByteArrayInputStream(outStream.toByteArray()); int inBytes = inStream.available(); System.out.println("inStream has " + inBytes + " available bytes"); byte inBuf[] = new byte[inBytes]; int bytesRead = inStream.read(inBuf, 0, inBytes); System.out.println(bytesRead + " bytes were read"); System.out.println("They are: " + new String(inBuf)); }
From source file:Main.java
public static void main(String[] args) { String numbers = "1234567890"; for (int i = 0; i < numbers.length(); i++) { if (Character.isDigit(numbers.charAt(i))) { System.out.println(numbers.charAt(i) + " is a number."); } else {//from w w w. ja va2 s . c om System.out.println(numbers.charAt(i) + " not a number."); } } }
From source file:ByteArrayIOApp.java
public static void main(String args[]) throws IOException { ByteArrayOutputStream outStream = new ByteArrayOutputStream(); String s = "This is a test."; for (int i = 0; i < s.length(); ++i) outStream.write(s.charAt(i)); System.out.println("outstream: " + outStream); System.out.println("size: " + outStream.size()); ByteArrayInputStream inStream; inStream = new ByteArrayInputStream(outStream.toByteArray()); int inBytes = inStream.available(); System.out.println("inStream has " + inBytes + " available bytes"); byte inBuf[] = new byte[inBytes]; int bytesRead = inStream.read(inBuf, 0, inBytes); System.out.println(bytesRead + " bytes were read"); System.out.println("They are: " + new String(inBuf)); }
From source file:Main.java
public static void main(String args[]) throws IOException { StringWriter outStream = new StringWriter(); String s = "This is a test from j a va2s.com."; for (int i = 0; i < s.length(); ++i) outStream.write(s.charAt(i)); System.out.println("outstream: " + outStream); System.out.println("size: " + outStream.toString().length()); }
From source file:StringIOApp.java
public static void main(String args[]) throws IOException { StringWriter outStream = new StringWriter(); String s = "This is a test."; for (int i = 0; i < s.length(); ++i) outStream.write(s.charAt(i)); System.out.println("outstream: " + outStream); System.out.println("size: " + outStream.toString().length()); StringReader inStream;//from ww w.j av a 2 s. com inStream = new StringReader(outStream.toString()); int ch = 0; StringBuffer sb = new StringBuffer(""); while ((ch = inStream.read()) != -1) sb.append((char) ch); s = sb.toString(); System.out.println(s.length() + " characters were read"); System.out.println("They are: " + s); }
From source file:Main.java
public static void main(String args[]) throws IOException { CharArrayWriter outStream = new CharArrayWriter(); String s = "This is a test."; for (int i = 0; i < s.length(); ++i) outStream.write(s.charAt(i)); System.out.println("outstream: " + outStream); System.out.println("size: " + outStream.size()); CharArrayReader inStream;/* ww w . j av a 2s . co m*/ inStream = new CharArrayReader(outStream.toCharArray()); int ch = 0; StringBuffer sb = new StringBuffer(""); while ((ch = inStream.read()) != -1) sb.append((char) ch); s = sb.toString(); System.out.println(s.length() + " characters were read"); System.out.println("They are: " + s); }
From source file:Main.java
public static void main(String[] args) { Map<Character, Integer> map = new TreeMap<>(); String blah = "aaaabbbbddd"; for (int i = 0; i < blah.length(); i++) { char c = blah.charAt(i); if (!map.containsKey(c)) { map.put(c, 1);/*from ww w .j a v a2 s .co m*/ } else { map.put(c, (map.get(c) + 1)); } } for (Map.Entry<Character, Integer> entry : map.entrySet()) { System.out.print(entry.getKey() + "" + entry.getValue()); } }
From source file:FileIOApp.java
public static void main(String args[]) throws IOException { FileOutputStream outStream = new FileOutputStream("test.txt"); String s = "This is a test."; for (int i = 0; i < s.length(); ++i) outStream.write(s.charAt(i)); outStream.close();//from www.j a v a2 s . c o m FileInputStream inStream = new FileInputStream("test.txt"); int inBytes = inStream.available(); System.out.println("inStream has " + inBytes + " available bytes"); byte inBuf[] = new byte[inBytes]; int bytesRead = inStream.read(inBuf, 0, inBytes); System.out.println(bytesRead + " bytes were read"); System.out.println("They are: " + new String(inBuf)); inStream.close(); File f = new File("test.txt"); f.delete(); }
From source file:Main.java
public static void main(String args[]) throws IOException { StringWriter outStream = new StringWriter(100); String s = "This is a test from j a va2s.com."; for (int i = 0; i < s.length(); ++i) { outStream.write(s.charAt(i)); }// w ww .jav a 2 s .co m System.out.println("outstream: " + outStream); System.out.println("size: " + outStream.toString().length()); }