Example usage for java.lang String length

List of usage examples for java.lang String length

Introduction

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

Prototype

public int length() 

Source Link

Document

Returns the length of this string.

Usage

From source file:Snippet19.java

public static void main(String[] args) {
    Display display = new Display();
    Shell shell = new Shell(display);
    Text text = new Text(shell, SWT.BORDER | SWT.V_SCROLL);
    text.setBounds(10, 10, 200, 200);/*from   w ww.j a v a 2  s .c o m*/
    text.addListener(SWT.Verify, new Listener() {
        public void handleEvent(Event e) {
            String string = e.text;
            char[] chars = new char[string.length()];
            string.getChars(0, chars.length, chars, 0);
            for (int i = 0; i < chars.length; i++) {
                if (!('0' <= chars[i] && chars[i] <= '9')) {
                    e.doit = false;
                    return;
                }
            }
        }
    });
    shell.open();
    while (!shell.isDisposed()) {
        if (!display.readAndDispatch())
            display.sleep();
    }
    display.dispose();
}

From source file:MarkVowels.java

public static void main(String[] args) {
    System.out.print("Enter a string: ");
    String s = sc.nextLine();
    String originalString = s;//w ww  .j  ava 2  s  . c o  m

    for (int i = 0; i < s.length(); i++) {
        char c = s.charAt(i);
        if ((c == 'A') || (c == 'a') || (c == 'E') || (c == 'e') || (c == 'I') || (c == 'i') || (c == 'O')
                || (c == 'o') || (c == 'U') || (c == 'u')) {
            String front = s.substring(0, i);
            String back = s.substring(i + 1);
            s = front + "*" + back;
        }
    }
    System.out.println(originalString);
    System.out.println(s);
}

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) {
    String searchMe = "Green Eggs and Ham";
    String findMe = "Eggs";
    int searchMeLength = searchMe.length();
    int findMeLength = findMe.length();
    boolean foundIt = false;
    for (int i = 0; i <= (searchMeLength - findMeLength); i++) {
        if (searchMe.regionMatches(i, findMe, 0, findMeLength)) {
            foundIt = true;//from   www. java 2 s  . co m
            System.out.println(searchMe.substring(i, i + findMeLength));
            break;
        }
    }
    if (!foundIt)
        System.out.println("No match found.");
}

From source file:TabFilter.java

public static void main(String args[]) throws Exception {
    FileReader fr = new FileReader(args[0]);
    BufferedReader br = new BufferedReader(fr);

    FileWriter fw = new FileWriter(args[1]);
    BufferedWriter bw = new BufferedWriter(fw);

    // Convert tab to space characters
    String s;
    while ((s = br.readLine()) != null) {
        for (int i = 0; i < s.length(); i++) {
            char c = s.charAt(i);
            if (c == '\t')
                c = ' ';
            bw.write(c);//  w w w .  j  av  a2 s  .com
        }
    }

    bw.flush();
    fr.close();
    fw.close();
}

From source file:com.sm.store.server.RemoteReplicaServer.java

public static void main(String[] args) {
    String[] opts = new String[] { "-configPath", "-start" };
    String[] defaults = new String[] { "./config", "true" };
    String[] paras = getOpts(args, opts, defaults);

    String configPath = paras[0];
    if (configPath.length() == 0) {
        logger.error("missing config path");
        throw new RuntimeException("missing -configPath");
    }//from  w  w w .j  a  v a  2  s  . com
    //make sure path is in proper format
    configPath = getPath(configPath);
    boolean start = Boolean.valueOf(paras[1]);
    logger.info("read stores.xml from " + configPath);
    BuildRemoteConfig bsc = new BuildRemoteConfig(configPath + "/stores.xml");
    RemoteStoreServer cs = new RemoteStoreServer(bsc.build());
    logger.info("hookup jvm shutdown process");
    cs.hookShutdown();
    if (start) {
        logger.info("server is starting " + cs.toString());
        cs.startServer();
    } else
        logger.warn("server is staged and wait to be started");
    List list = new ArrayList();
    //add jmx metric
    List<String> stores = cs.getAllStoreNames();
    for (String store : stores) {
        list.add(cs.getRemoteStore(store));
    }
    list.add(cs);
    JmxService jms = new JmxService(list);
}

From source file:Main.java

public static void main(String[] args) {
    String input = "test";
    Stack<Character> stack = new Stack<Character>();
    for (int i = 0; i < input.length(); i++) {
        stack.push(input.charAt(i));//from  ww  w.  j  a va 2  s. co  m
    }
    String reverseInput = "";
    while (!stack.isEmpty()) {
        reverseInput += stack.pop();
    }
    if (input.equals(reverseInput)) {
        System.out.println("Yo! that is a palindrome.");
    } else {
        System.out.println("No! that isn't a palindrome.");
    }
}

From source file:SafeCollectionIteration.java

public static void main(String[] args) {
    List wordList = Collections.synchronizedList(new ArrayList());

    wordList.add("Iterators");
    wordList.add("require");
    wordList.add("special");
    wordList.add("handling");

    synchronized (wordList) {
        Iterator iter = wordList.iterator();
        while (iter.hasNext()) {
            String s = (String) iter.next();
            System.out.println("found string: " + s + ", length=" + s.length());
        }/*  w w  w .j  a  v a 2  s .  co  m*/
    }
}

From source file:com.thesoftwareguild.capstoneblog.controller.PWEnc.java

public static void main(String[] args) {
    String clearTxtPw = "password";
    // BCrypt//w ww  .  ja v a2 s.c o m
    BCryptPasswordEncoder encoder = new BCryptPasswordEncoder();
    String hashedPw = encoder.encode(clearTxtPw);
    System.out.println(hashedPw);
    System.out.println(hashedPw.length());

}

From source file:OldStyle.java

public static void main(String args[]) {
    ArrayList list = new ArrayList();

    list.add("one");
    list.add("two");
    list.add("three");
    list.add("four");

    Iterator itr = list.iterator();
    while (itr.hasNext()) {
        String str = (String) itr.next(); // explicit cast needed here.

        System.out.println(str + " is " + str.length() + " chars long.");
    }//from ww w.  j  av a  2s  .c  o  m
}