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:ricecompression.RiceCompression.java

/**
 * @param args the command line arguments
 *///w  w  w.  j a  v  a 2 s  .  c o  m
public static void main(String[] args) {
    RiceCompression rice = new RiceCompression();
    XYSeries data = new XYSeries("RICE");
    for (int i = -1023; i < 1024; i++) {
        String riceCode = rice.compress(32, i);
        data.add(i, riceCode.length());
    }
    XYSeriesCollection collection = new XYSeriesCollection(data);
    JFreeChart grafica = ChartFactory.createXYLineChart("RICE", "Nmero a codificar", "Longitud del codi Rice",
            collection, PlotOrientation.VERTICAL, true, true, false);
    ChartPanel Panel = new ChartPanel(grafica);
    JFrame Ventana = new JFrame("JFreeChart");
    Ventana.getContentPane().add(Panel);
    Ventana.pack();
    Ventana.setVisible(true);
    Ventana.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
}

From source file:com.sm.store.server.grizzly.RemoteScan4ReplicaServer.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  ww . jav  a 2s  .co  m
    //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");
    GZScan4RemoteServer cs = new GZScan4RemoteServer(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));
    }
    // add additional name into list for Scan4RemoteServer
    list.add(cs);
    stores.add("Scan4RemoteServer");
    JmxService jms = new JmxService(list, stores);
}

From source file:com.sm.store.server.netty.RemoteScan4ReplicaServer.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  ww  w  .  j  av a  2 s.c  o  m
    //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");
    Scan4RemoteServer cs = new Scan4RemoteServer(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));
    }
    // add additional name into list for Scan4RemoteServer
    list.add(cs);
    stores.add("Scan4RemoteServer");
    JmxService jms = new JmxService(list, stores);
}

From source file:MainClass.java

public static void main(String[] args) {
    try {//from  w  w w .ja  v  a  2 s  . co m
        Class c = Class.forName("java.util.ArrayList");

        Constructor constructors[] = c.getDeclaredConstructors();
        for (int i = 0; i < constructors.length; i++) {
            System.out.print(constructors[i].getName() + ": ");
            Class parameters[];
            parameters = constructors[i].getParameterTypes();
            for (int j = 0; j < parameters.length; j++) {
                String s = parameters[j].getName();
                s = s.substring(s.lastIndexOf(".") + 1, s.length());
                System.out.print(s + " ");
            }
            System.out.println("");
        }
    } catch (Exception ex) {
        ex.printStackTrace();
    }
}

From source file:MainClass.java

public static void main(String[] args) {
    try {/*  w ww  .  ja  v  a  2s . co m*/
        Class c = Class.forName("java.util.ArrayList");

        Constructor constructors[] = c.getConstructors();
        for (int i = 0; i < constructors.length; i++) {
            System.out.print(constructors[i].getName() + ": ");
            Class parameters[];
            parameters = constructors[i].getParameterTypes();
            for (int j = 0; j < parameters.length; j++) {
                String s = parameters[j].getName();
                s = s.substring(s.lastIndexOf(".") + 1, s.length());
                System.out.print(s + " ");
            }
            System.out.println("");
        }
    } catch (Exception ex) {
        ex.printStackTrace();
    }
}

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 w  w .ja va2 s.  c  om*/
        if (Character.isLetter(ch))
            ++letters;
        if (Character.isWhitespace(ch))
            ++spaces;
    }
}

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  av  a2  s  .c  o m
    }
    System.out.println("String >>" + strTest);
    System.out.println("Number of vowels in the string is " + iVowelCnt);
}

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

From source file:MainClass.java

public static void main(String args[]) throws Exception {
    final String START_STRING = "Start\n";
    final int START_STRING_LENGTH = START_STRING.length();

    JFrame frame = new JFrame("Navigation Example");
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

    JTextArea textArea = new JTextArea(START_STRING);
    textArea.setCaretPosition(START_STRING_LENGTH);
    JScrollPane scrollPane = new JScrollPane(textArea);
    frame.add(scrollPane, BorderLayout.CENTER);

    NavigationFilter filter = new NavigationFilter() {
        public void setDot(NavigationFilter.FilterBypass fb, int dot, Position.Bias bias) {
            if (dot < START_STRING_LENGTH) {
                fb.setDot(START_STRING_LENGTH, bias);
            } else {
                fb.setDot(dot, bias);/*from www .  j  a  va  2 s .  c om*/
            }
        }

        public void moveDot(NavigationFilter.FilterBypass fb, int dot, Position.Bias bias) {
            if (dot < START_STRING_LENGTH) {
                fb.setDot(START_STRING_LENGTH, bias);
            } else {
                fb.setDot(dot, bias);
            }
        }
    };

    textArea.setNavigationFilter(filter);

    frame.setSize(250, 150);
    frame.setVisible(true);
}

From source file:Main.java

public static void main(String[] args) {
    String str1 = new String();
    String str2 = new String("Hello");

    // Get the length of str1 and str2 
    int len1 = str1.length();
    int len2 = str2.length();

    // Display the length of str1 and str2
    System.out.println("Length of  \"" + str1 + "\" = " + len1);
    System.out.println("Length of  \"" + str2 + "\" = " + len2);
}