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:TasteOfThingsV1.java

 public static void main(String args[]) throws Exception {
   prepareData();/*  w  w  w  . j a v  a2s  . com*/

   HashBag myBag = new HashBag(testMap.values());

   System.err.println("How many Boxes? " + myBag.getCount("Boxes"));
   myBag.add("Boxes", 5);
   System.err.println("How many Boxes now? " + myBag.getCount("Boxes"));

   Method method =
     testBean.getClass().getDeclaredMethod("getTestMap", new Class[0]);
   HashMap reflectionMap =
     (HashMap)method.invoke(testBean, new Object[0]);
   System.err.println("The value of the 'squ' key using reflection: " +
     reflectionMap.get("squ"));

   String squ = BeanUtils.getMappedProperty(testBean, "testMap", "squ");
   squ = StringUtils.capitalize(squ);

   PropertyUtils.setMappedProperty(testBean, "testMap", "squ", squ);

   System.err.println("The value of the 'squ' key is: " +
     BeanUtils.getMappedProperty(testBean, "testMap", "squ"));

   String box = (String)testMap.get("box");
   String caps =
     Character.toTitleCase(box.charAt(0)) +
     box.substring(1, box.length());
   System.err.println("Capitalizing boxes by Java: " + caps);
}

From source file:StrCharAt.java

public static void main(String[] av) {
    String a = "A quick bronze fox lept a lazy bovine";
    for (int i = 0; i < a.length(); i++)
        System.out.println("Char " + i + " is " + a.charAt(i));
}

From source file:Main.java

public static void main(String[] args) {
    System.out.println("Enter a string");
    Scanner input = new Scanner(System.in);
    String s1 = input.nextLine();
    s1 = s1.trim();/*from w  w  w  . jav a2s .co m*/
    int howLong = s1.length();

    for (int counter = 0; counter < howLong; counter++) {
        char ch = s1.charAt(counter);
        System.out.print(ch);
    }

}

From source file:StringCharacters.java

public static void main(String[] args) {
    String text = "To be or not to be?";

    int spaces = 0, vowels = 0, letters = 0;

    for (int i = 0; i < text.length(); i++) {
        char ch = Character.toLowerCase(text.charAt(i));
        if (ch == 'a' || ch == 'e' || ch == 'i' || ch == 'o' || ch == 'u')
            ++vowels;/*from  w ww . j  a  va 2 s  .  co  m*/
        if (Character.isLetter(ch))
            ++letters;
        if (Character.isWhitespace(ch))
            ++spaces;
    }
}

From source file:ComputeResult.java

public static void main(String[] args) {
    String original = "software";
    StringBuilder result = new StringBuilder("hi");
    int index = original.indexOf('a');

    /*1*/ result.setCharAt(0, original.charAt(0));
    /*2*/ result.setCharAt(1, original.charAt(original.length() - 1));
    /*3*/ result.insert(1, original.charAt(4));
    /*4*/ result.append(original.substring(1, 4));
    /*5*/ result.insert(3, (original.substring(index, index + 2) + " "));

    System.out.println(result);//from  w w  w .  j  a v a 2  s  . c  o  m
}

From source file:Main.java

public static void main(String[] args) {
    String string = "java 2s.com java";
    int length = string.length();
    if (length < 2) {
        System.out.println(string);
        return;//from   w ww .j  a  v  a 2 s  . c  o m
    }

    System.out.print(string.charAt(0));
    for (int i = 1; i < length; i++) {
        if (string.charAt(i) != string.charAt(i - 1)) {
            System.out.print(string.charAt(i));
        }
    }
}

From source file:MyTest.DownloadFileTest.java

public static void main(String args[]) {
    CloseableHttpClient httpclient = HttpClients.createDefault();
    String url = "http://www.myexperiment.org/workflows/16/download/Pathways_and_Gene_annotations_for_QTL_region-v7.t2flow?version=7";
    System.out.println(url.charAt(50));
    HttpGet httpget = new HttpGet(url);
    HttpEntity entity = null;/*w  ww .j av  a2  s  . c o  m*/
    try {
        HttpResponse response = httpclient.execute(httpget);
        entity = response.getEntity();
        if (entity != null) {
            InputStream is = entity.getContent();
            String filename = "testdata/Pathways_and_Gene_annotations_for_QTL_region-v7.t2flow";
            BufferedInputStream bis = new BufferedInputStream(is);
            BufferedOutputStream bos = new BufferedOutputStream(new FileOutputStream(new File(filename)));
            int readedByte;
            while ((readedByte = bis.read()) != -1) {
                bos.write(readedByte);
            }
            bis.close();
            bos.close();
        }
        httpclient.close();
    } catch (IOException ex) {
        Logger.getLogger(DownloadFileTest.class.getName()).log(Level.SEVERE, null, ex);
    }

}

From source file:AnagramApp.java

public static void main(String[] args) throws IOException {
    String input = "java2s.com";
    size = input.length();/*  w ww  .  j  a 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:MainClass.java

public static void main(String args[]) {
    String s1 = "hello there";
    char charArray[] = new char[5];

    System.out.printf("s1: %s", s1);

    for (int count = s1.length() - 1; count >= 0; count--)
        System.out.printf("%s ", s1.charAt(count));

    // copy characters from string into charArray
    s1.getChars(0, 5, charArray, 0);/*ww w  . java  2  s. co  m*/
    System.out.print("\nThe character array is: ");

    for (char character : charArray)
        System.out.print(character);
}

From source file:MainClass.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  w  w w. j  ava  2s  .c om
    }
    System.out.println("String >>" + strTest);
    System.out.println("Number of vowels in the string is " + iVowelCnt);
}