Example usage for java.lang String toCharArray

List of usage examples for java.lang String toCharArray

Introduction

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

Prototype

public char[] toCharArray() 

Source Link

Document

Converts this string to a new character array.

Usage

From source file:Main.java

public static void main(String[] argv) throws Exception {
    FileInputStream is = new FileInputStream("yourfile" + ".keystore");
    KeyStore keystore = KeyStore.getInstance(KeyStore.getDefaultType());
    String password = "my-keystore-password";
    keystore.load(is, password.toCharArray());

    Enumeration e = keystore.aliases();
    for (; e.hasMoreElements();) {
        String alias = (String) e.nextElement();

        boolean b = keystore.isKeyEntry(alias);

        b = keystore.isCertificateEntry(alias);
    }/*from   w  w w. java  2 s . c om*/
    is.close();
}

From source file:Main.java

public static void main(String[] argv) throws Exception {
    String filename = System.getProperty("java.home")
            + "/lib/security/cacerts".replace('/', File.separatorChar);
    FileInputStream is = new FileInputStream(filename);
    KeyStore keystore = KeyStore.getInstance(KeyStore.getDefaultType());
    String password = "password";
    keystore.load(is, password.toCharArray());

    PKIXParameters params = new PKIXParameters(keystore);

    params.setRevocationEnabled(false);//w  w w  . java2s.c o  m

    CertPathValidator certPathValidator = CertPathValidator.getInstance(CertPathValidator.getDefaultType());
    CertPath certPath = null;
    CertPathValidatorResult result = certPathValidator.validate(certPath, params);

    PKIXCertPathValidatorResult pkixResult = (PKIXCertPathValidatorResult) result;
    TrustAnchor ta = pkixResult.getTrustAnchor();
    X509Certificate cert = ta.getTrustedCert();
}

From source file:Main.java

public static void main(String args[]) {
    String name = "premkumarg";
    int len = name.length();
    char[] c = name.toCharArray();
    for (int i = 0; i < len - 1; i = i + 2) {
        char temp = c[i];
        c[i] = c[i + 1];//from w w  w.j  a  v a2  s  .  co  m
        c[i + 1] = temp;
    }

    System.out.println("Swapping string is: ");
    System.out.println(c);

}

From source file:Main.java

public static void main(String args[]) throws Exception {

    FileReader fr = new FileReader(args[0]);
    BufferedReader br = new BufferedReader(fr);

    // Process lines from file
    String line;
    while ((line = br.readLine()) != null) {
        char array[] = line.toCharArray();
        System.out.print(array[0]);
    }/* w  ww.jav a 2 s.  co  m*/
}

From source file:MainClass.java

public static void main(String[] arg) {
    String phrase = "The quick brown fox jumped over the lazy dog.";
    int vowels = 0;
    for (char ch : phrase.toCharArray()) {
        ch = Character.toLowerCase(ch);
        if (ch == 'a' || ch == 'e' || ch == 'i' || ch == 'o' || ch == 'u') {
            ++vowels;//  w  w  w.  ja  va2  s. co m
        }
    }
    System.out.println("The phrase contains " + vowels + " vowels.");
}

From source file:Main.java

public static void main(String[] args) {
    String yourString = "UNDERSTAND";
    Map<Character, Integer> count = new TreeMap<Character, Integer>();
    for (char c : yourString.toCharArray()) {
        if (count.containsKey(c)) {
            count.put(c, (int) count.get(c) + 1);
        } else {/*from ww w. j  av  a  2 s .c  o  m*/
            count.put(c, 1);
        }
    }
    System.out.println(count);
}

From source file:CAList.java

/**
 * <p><!-- Method description --></p>
 *
 *
 * @param args/*from  ww w .j  a va2s .c  om*/
 */
public static void main(String[] args) {
    try {
        // Load the JDK's cacerts keystore file
        String filename = System.getProperty("java.home")
                + "/lib/security/cacerts".replace('/', File.separatorChar);
        FileInputStream is = new FileInputStream(filename);
        KeyStore keystore = KeyStore.getInstance(KeyStore.getDefaultType());
        String password = "changeit";
        keystore.load(is, password.toCharArray());

        // This class retrieves the most-trusted CAs from the keystore
        PKIXParameters params = new PKIXParameters(keystore);

        // Get the set of trust anchors, which contain the most-trusted CA certificates
        Iterator it = params.getTrustAnchors().iterator();
        for (; it.hasNext();) {
            TrustAnchor ta = (TrustAnchor) it.next();

            // Get certificate
            X509Certificate cert = ta.getTrustedCert();
            System.out.println("<issuer>" + cert.getIssuerDN() + "</issuer>\n");
        }
    } catch (CertificateException e) {
    } catch (KeyStoreException e) {
    } catch (NoSuchAlgorithmException e) {
    } catch (InvalidAlgorithmParameterException e) {
    } catch (IOException e) {
    }
}

From source file:com.vimukti.accounter.developer.api.PublicKeyGenerator.java

/**
 * @param args/* www. j ava2s.c  o  m*/
 * @throws NoSuchProviderException
 * @throws NoSuchAlgorithmException
 * @throws InvalidKeySpecException
 * @throws IOException
 * @throws CertificateException
 * @throws KeyStoreException
 * @throws UnrecoverableEntryException
 * @throws URISyntaxException
 */
public static void main(String[] args) throws KeyStoreException, NoSuchAlgorithmException, CertificateException,
        IOException, UnrecoverableEntryException {
    FileInputStream is = new FileInputStream(
            ServerConfiguration.getConfig() + File.separator + "license.keystore");
    KeyStore keystore = KeyStore.getInstance(KeyStore.getDefaultType());
    String password = "liceseStorePassword";
    keystore.load(is, password.toCharArray());
    PrivateKeyEntry entry = (PrivateKeyEntry) keystore.getEntry("licenseAlias",
            new PasswordProtection(ServerConfiguration.getLicenseKeystorePWD().toCharArray()));
    Key key = entry.getPrivateKey();
    System.out.println((PrivateKey) key);
    PublicKey publicKey = entry.getCertificate().getPublicKey();
    System.out.println(publicKey);

    byte[] encoded = publicKey.getEncoded();
    byte[] encodeBase64 = Base64.encodeBase64(encoded);
    System.out.println("Public Key:" + new String(encodeBase64));

}

From source file:Main.java

public static void main(String[] args) throws IOException {

    String letters = "from java2s.com";

    StringWriter sw = new StringWriter();

    BufferedWriter bw = new BufferedWriter(sw);

    for (char c : letters.toCharArray()) {

        bw.append(c);/*from  www.  j  a v a2  s  .  co  m*/

        bw.flush();

        System.out.println(sw.getBuffer());
    }

}

From source file:Main.java

public static void main(String[] args) throws Exception {
    String ch = "this is a test this is a test test is is is a a a a a a a";
    int count = 0, len = 0;
    do {/*from  w w w.  jav a2  s. co m*/
        try {
            char name[] = ch.toCharArray();
            len = name.length;
            count = 0;
            for (int j = 0; j < len; j++) {
                if ((name[0] == name[j])
                        && ((name[0] >= 65 && name[0] <= 91) || (name[0] >= 97 && name[0] <= 123)))
                    count++;
            }
            if (count != 0)
                System.out.println(name[0] + " " + count + " Times");
            ch = ch.replace("" + name[0], "");
        } catch (Exception ex) {
        }
    } while (len != 1);
}