Example usage for java.lang String charAt

List of usage examples for java.lang String charAt

Introduction

In this page you can find the example usage for java.lang String charAt.

Prototype

public char charAt(int index) 

Source Link

Document

Returns the char value at the specified index.

Usage

From source file:com.mycompany.mavenproject1.Ex1.java

public static void main(String[] args) {
    Ex1 obj = new Ex1();
    String data = obj.getFileWithUtil("data.json");
    for (int i = 0; i < data.length(); i++) {
        System.out.println(Integer.toBinaryString(data.charAt(i)));
    }/* w  w w  . j  av  a  2 s.co  m*/
}

From source file:VowelCharSetTrial.java

public static void main(String[] args) {
    // Create a new vowel character set
    CharSet vChs = CharSet.getInstance("aeiou");

    String strTest = "The quick brown fox jumps over the lazy dog.";
    int iVowelCnt = 0;
    int iTestLen = strTest.length();

    for (int i = 0; i < iTestLen; i++) {
        if (vChs.contains(strTest.charAt(i))) {
            iVowelCnt++; // increment count on a vowel being found
        }//from   www  . j a  va 2  s  . c om
    }
    System.out.println("String >>" + strTest);
    System.out.println("Number of vowels in the string is " + iVowelCnt);
}

From source file:KeyEventPost.java

public static void main(String[] args) {
    final Display display = new Display();
    final Shell shell = new Shell(display);
    final Text text = new Text(shell, SWT.BORDER);
    text.setSize(text.computeSize(150, SWT.DEFAULT));
    shell.pack();/*from ww w.j  a  va2  s  .c om*/
    shell.open();
    new Thread() {
        public void run() {
            String string = "Love the method.";
            for (int i = 0; i < string.length(); i++) {
                char ch = string.charAt(i);
                boolean shift = Character.isUpperCase(ch);
                ch = Character.toLowerCase(ch);
                if (shift) {
                    Event event = new Event();
                    event.type = SWT.KeyDown;
                    event.keyCode = SWT.SHIFT;
                    display.post(event);
                }
                Event event = new Event();
                event.type = SWT.KeyDown;
                event.character = ch;
                display.post(event);
                try {
                    Thread.sleep(10);
                } catch (InterruptedException e) {
                }
                event.type = SWT.KeyUp;
                display.post(event);
                try {
                    Thread.sleep(100);
                } catch (InterruptedException e) {
                }
                if (shift) {
                    event = new Event();
                    event.type = SWT.KeyUp;
                    event.keyCode = SWT.SHIFT;
                    display.post(event);
                }
            }
        }
    }.start();
    while (!shell.isDisposed()) {
        if (!display.readAndDispatch())
            display.sleep();
    }
    display.dispose();
}

From source file:Stack.java

public static void main(String[] args) {
    String input = "input";
    int stackSize = input.length();

    Stack theStack = new Stack(stackSize);

    for (int j = 0; j < input.length(); j++) {
        char ch = input.charAt(j);
        theStack.push(ch);//from w  w w.j a  va 2  s.  co  m
    }

    while (!theStack.isEmpty()) {
        char ch = theStack.pop();
        System.out.println(ch);
    }
}

From source file:AnagramApp.java

public static void main(String[] args) throws IOException {
    String input = "Java Source and Support";
    size = input.length();//from  w w w .ja  v  a 2 s. c om
    count = 0;
    charArray = new char[size];
    for (int j = 0; j < size; j++)
        charArray[j] = input.charAt(j);
    doAnagram(size);
}

From source file:Main.java

public static void main(String[] args) {
    String str = "JAVA2S.COM";

    // Get the length of string
    int len = str.length();

    // Loop through all characters and print their indexes
    for (int i = 0; i < len; i++) {
        System.out.println(str.charAt(i) + "  has  index   " + i);
    }/*from  ww w . ja  va2s  .co  m*/

}

From source file:Main.java

public static void main(String[] args) throws IOException {
    String input = "this is a test";
    StringBuilder result = new StringBuilder();
    char currentCharacter;
    int count;//from w w w  . j av  a  2s.co  m

    for (int i = 0; i < input.length(); i++) {
        currentCharacter = input.charAt(i);
        count = 1;
        while (i < input.length() - 1 && input.charAt(i + 1) == currentCharacter) {
            count++;
            i++;
        }
        result.append(currentCharacter);
        result.append(count);
    }

    System.out.println("" + result);
}

From source file:StringsDemo.java

public static void main(String[] args) {
    String palindrome = "Dot saw I was Tod";
    int len = palindrome.length();
    StringBuffer dest = new StringBuffer(len);

    for (int i = (len - 1); i >= 0; i--) {
        dest.append(palindrome.charAt(i));
    }/*from   w ww .jav a2s.  co m*/
    System.out.println(dest.toString());
}

From source file:ComputeInitials.java

public static void main(String[] args) {
    String myName = "Fred F. Flintstone";
    StringBuffer myInitials = new StringBuffer();
    int length = myName.length();

    for (int i = 0; i < length; i++) {
        if (Character.isUpperCase(myName.charAt(i))) {
            myInitials.append(myName.charAt(i));
        }/*from   ww  w.java 2 s .com*/
    }
    System.out.println("My initials are: " + myInitials);
}

From source file:org.eclipse.swt.snippets.Snippet146.java

public static void main(String[] args) {
    final Display display = new Display();
    final Shell shell = new Shell(display);
    shell.setText("Snippet 146");
    final Text text = new Text(shell, SWT.BORDER);
    text.setSize(text.computeSize(150, SWT.DEFAULT));
    shell.pack();//from ww  w .  j  av a 2s .  c  o m
    shell.open();
    new Thread() {
        @Override
        public void run() {
            // wait for shell to be opened
            try {
                Thread.sleep(100);
            } catch (InterruptedException e) {
            }

            String string = "Love the method.";
            for (int i = 0; i < string.length(); i++) {
                char ch = string.charAt(i);
                boolean shift = Character.isUpperCase(ch);
                ch = Character.toLowerCase(ch);
                if (shift) {
                    Event event = new Event();
                    event.type = SWT.KeyDown;
                    event.keyCode = SWT.SHIFT;
                    display.post(event);
                }
                Event event = new Event();
                event.type = SWT.KeyDown;
                event.character = ch;
                display.post(event);
                try {
                    Thread.sleep(10);
                } catch (InterruptedException e) {
                }
                event.type = SWT.KeyUp;
                display.post(event);
                try {
                    Thread.sleep(100);
                } catch (InterruptedException e) {
                }
                if (shift) {
                    event = new Event();
                    event.type = SWT.KeyUp;
                    event.keyCode = SWT.SHIFT;
                    display.post(event);
                }
            }
        }
    }.start();
    while (!shell.isDisposed()) {
        if (!display.readAndDispatch())
            display.sleep();
    }
    display.dispose();
}