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

public static void main(String args[]) {
    String strOb1 = "First String";
    String strOb2 = "Second String";
    String strOb3 = strOb1;//from  w  ww .ja va 2s  . co m

    System.out.println("Length of strOb1: " + strOb1.length());

    System.out.println("Char at index 3 in strOb1: " + strOb1.charAt(3));

    if (strOb1.equals(strOb2))
        System.out.println("strOb1 == strOb2");
    else
        System.out.println("strOb1 != strOb2");

    if (strOb1.equals(strOb3))
        System.out.println("strOb1 == strOb3");
    else
        System.out.println("strOb1 != strOb3");
}

From source file:com.daoke.mobileserver.test.TestHttps.java

public static void main(String args[]) {
    /*//from  w ww.  java2 s . c o m
            AtomicInteger a = new AtomicInteger();
            
            a.getAndIncrement();*/
    String str = "version,ordertype,username,outerno,companyno,insuredperson,plcstartdate,plcenddate,licenseno,nolicenseflag,ownername,owneridno,ownercerttype,ownercertno,citycode,cardno,firstregisterdate,vehiclemodelname,vehicleid,vehicleframeno,engineno,vehicleinvoiceno,vehicleinvoicedate,runcardcertificatedate,forcebegindate,bizbegindate,taxvehicletype,fueltype,specialcarflag,specialcardate,persontaxcode,taxticketno,taxtickettype,taxbureauname,settledaddress,vehicleseats,averagemile,trafficviolation,bizquestion,bizanswer,forcequestion,forceanswer,vehiclecode,vehiclecodename,sessionid,trafficinsurance,traveltax,remark1,remark2,remark3,remark4,remark5,remark6,remark7,remark8,remark9,remark10,remark11,remark12,remark13,remark14,remark15,step,linkInfo_name,linkInfo_mobile,linkInfo_address,linkInfo_invoice,linkInfo_zipcode,linkInfo_email,linkInfo_paytype,linkInfo_realpaymode,insurInfo_name,insurInfo_certtype,insurInfo_certno,insurInfo_sex,insurInfo_birth,insurInfo_email,aplInfo_name,aplInfo_certtype,aplInfo_certno,aplInfo_sex,aplInfo_birth,aplInfo_email,businesspremium,forcepremium,vehicletaxamount,realpremium,totalremium,configbeforejudge";
    String[] strs = str.split(",");
    for (String str1 : strs) {
        String str2 = str1.replace(str1.charAt(0), (char) (str1.charAt(0) - 32));
        System.out.print("ejsinoFormModel.get" + str2 + "(),");
    }

    /*   Date a = new Date(123);
       SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
       sdf.format(a);
       System.out.println(a.getTime());
       System.out.println( sdf.format(a));*/

    /*   TestHttps test = new TestHttps();
       try {
          String resp = test.doPost("https://192.168.11.93:1500/lua",null,DEFAULT_CHARSET,2000,1000);
    System.out.println(resp);
       } catch (Exception e) {
    e.printStackTrace();
       }*/
}

From source file:example.Publisher.java

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

    String user = env("ACTIVEMQ_USER", "admin");
    String password = env("ACTIVEMQ_PASSWORD", "password");
    String host = env("ACTIVEMQ_HOST", "localhost");
    int port = Integer.parseInt(env("ACTIVEMQ_PORT", "1883"));
    final String destination = arg(args, 0, "/topic/event");

    int messages = 10000;
    int size = 256;

    String DATA = "abcdefghijklmnopqrstuvwxyz";
    String body = "";
    for (int i = 0; i < size; i++) {
        body += DATA.charAt(i % DATA.length());
    }//  ww w  . j a va 2s. c  o m
    Buffer msg = new AsciiBuffer(body);

    MQTT mqtt = new MQTT();
    mqtt.setHost(host, port);
    mqtt.setUserName(user);
    mqtt.setPassword(password);

    FutureConnection connection = mqtt.futureConnection();
    connection.connect().await();

    final LinkedList<Future<Void>> queue = new LinkedList<Future<Void>>();
    UTF8Buffer topic = new UTF8Buffer(destination);
    for (int i = 1; i <= messages; i++) {

        // Send the publish without waiting for it to complete. This allows us
        // to send multiple message without blocking..
        queue.add(connection.publish(topic, msg, QoS.AT_LEAST_ONCE, false));

        // Eventually we start waiting for old publish futures to complete
        // so that we don't create a large in memory buffer of outgoing message.s
        if (queue.size() >= 1000) {
            queue.removeFirst().await();
        }

        if (i % 1000 == 0) {
            System.out.println(String.format("Sent %d messages.", i));
        }
    }

    queue.add(connection.publish(topic, new AsciiBuffer("SHUTDOWN"), QoS.AT_LEAST_ONCE, false));
    while (!queue.isEmpty()) {
        queue.removeFirst().await();
    }

    connection.disconnect().await();

    System.exit(0);
}

From source file:Main.java

public static void main(String[] args) throws Exception {
    SimpleDateFormat simpleDateFormat = new SimpleDateFormat("dd-MM-yyyy");
    String trouble = "18?11?2003";
    String goodOne = "18-11-2003";
    Date date = simpleDateFormat.parse(goodOne);
    System.out.println(date);//w w w . ja va  2s  . c  o  m
    date = simpleDateFormat.parse(trouble);
    System.out.println(date);
    System.out.println(String.format("\\u%04x", (int) trouble.charAt(2)));
    System.out.println(String.format("\\u%04x", (int) goodOne.charAt(2)));

}

From source file:SyntaxColoring.java

public static void main(String[] args) {
    final Display display = new Display();
    final Shell shell = new Shell(display);

    final StyledText styledText = new StyledText(shell, SWT.V_SCROLL | SWT.BORDER);

    final String PUNCTUATION = "(){}";
    styledText.addExtendedModifyListener(new ExtendedModifyListener() {
        public void modifyText(ExtendedModifyEvent event) {
            int end = event.start + event.length - 1;

            if (event.start <= end) {
                String text = styledText.getText(event.start, end);
                java.util.List ranges = new java.util.ArrayList();

                for (int i = 0, n = text.length(); i < n; i++) {
                    if (PUNCTUATION.indexOf(text.charAt(i)) > -1) {
                        ranges.add(new StyleRange(event.start + i, 1, display.getSystemColor(SWT.COLOR_BLUE),
                                null, SWT.BOLD));
                    }//from   ww w . j  ava  2 s.  co m
                }
                if (!ranges.isEmpty()) {
                    styledText.replaceStyleRanges(event.start, event.length,
                            (StyleRange[]) ranges.toArray(new StyleRange[0]));
                }
            }
        }
    });

    styledText.setBounds(10, 10, 500, 100);
    shell.open();
    while (!shell.isDisposed()) {
        if (!display.readAndDispatch()) {
            display.sleep();
        }
    }
    display.dispose();
}

From source file:Main.java

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

    // put original string in an array of chars
    for (int i = 0; i < len; i++) {
        tempCharArray[i] = palindrome.charAt(i);
    }/*from www  . j  av a  2s.  c o m*/

    // reverse array of chars
    for (int j = 0; j < len; j++) {
        charArray[j] = tempCharArray[len - 1 - j];
    }

    String reversePalindrome = new String(charArray);
    System.out.println(reversePalindrome);
}

From source file:ISMAGS.CommandLineInterface.java

public static void main(String[] args) throws IOException {
    String folder = null, files = null, motifspec = null, output = null;

    Options opts = new Options();
    opts.addOption("folder", true, "Folder name");
    opts.addOption("linkfiles", true,
            "Link files seperated by spaces (format: linktype[char] directed[d/u] filename)");
    opts.addOption("motif", true, "Motif description by two strings (format: linktypes)");
    opts.addOption("output", true, "Output file name");

    CommandLineParser parser = new PosixParser();
    try {//from www. j av  a2s.co  m
        CommandLine cmd = parser.parse(opts, args);
        if (cmd.hasOption("folder")) {
            folder = cmd.getOptionValue("folder");
        }
        if (cmd.hasOption("linkfiles")) {
            files = cmd.getOptionValue("linkfiles");
        }
        if (cmd.hasOption("motif")) {
            motifspec = cmd.getOptionValue("motif");
        }
        if (cmd.hasOption("output")) {
            output = cmd.getOptionValue("output");
        }
    } catch (ParseException e) {
        Die("Error: Parsing error");
    }

    if (print) {
        printBanner(folder, files, motifspec, output);
    }

    if (folder == null || files == null || motifspec == null || output == null) {
        Die("Error: not all options are provided");
    } else {
        ArrayList<String> linkfiles = new ArrayList<String>();
        ArrayList<String> linkTypes = new ArrayList<String>();
        ArrayList<String> sourcenetworks = new ArrayList<String>();
        ArrayList<String> destinationnetworks = new ArrayList<String>();
        ArrayList<Boolean> directed = new ArrayList<Boolean>();
        StringTokenizer st = new StringTokenizer(files, " ");
        while (st.hasMoreTokens()) {
            linkTypes.add(st.nextToken());
            directed.add(st.nextToken().equals("d"));
            sourcenetworks.add(st.nextToken());
            destinationnetworks.add(st.nextToken());
            linkfiles.add(folder + st.nextToken());
        }
        ArrayList<LinkType> allLinkTypes = new ArrayList<LinkType>();
        HashMap<Character, LinkType> typeTranslation = new HashMap<Character, LinkType>();
        for (int i = 0; i < linkTypes.size(); i++) {
            String n = linkTypes.get(i);
            char nn = n.charAt(0);
            LinkType t = typeTranslation.get(nn);
            if (t == null) {
                t = new LinkType(directed.get(i), n, i, nn, sourcenetworks.get(i), destinationnetworks.get(i));
            }
            allLinkTypes.add(t);
            typeTranslation.put(nn, t);
        }
        if (print) {
            System.out.println("Reading network..");
        }
        Network network = Network.readNetworkFromFiles(linkfiles, allLinkTypes);

        Motif motif = getMotif(motifspec, typeTranslation);

        if (print) {
            System.out.println("Starting the search..");
        }
        MotifFinder mf = new MotifFinder(network);
        long tijd = System.nanoTime();
        Set<MotifInstance> motifs = mf.findMotif(motif, false);
        tijd = System.nanoTime() - tijd;
        if (print) {
            System.out.println("Completed search in " + tijd / 1000000 + " milliseconds");
        }
        if (print) {
            System.out.println("Found " + motifs.size() + " instances of " + motifspec + " motif");
        }
        if (print) {
            System.out.println("Writing instances to file: " + output);
        }
        printMotifs(motifs, output);
        if (print) {
            System.out.println("Done.");
        }
        //            Set<MotifInstance> motifs=null;
        //            MotifFinder mf=null;
        //            System.out.println("Starting the search..");
        //            long tstart = System.nanoTime();
        //            for (int i = 0; i < it; i++) {
        //
        //                mf = new MotifFinder(network, allLinkTypes, true);
        //                motifs = mf.findMotif(motif);
        //            }
        //
        //            long tend = System.nanoTime();
        //            double time_in_ms = (tend - tstart) / 1000000.0;
        //            System.out.println("Found " + mf.totalFound + " motifs, " + time_in_ms + " ms");
        ////        System.out.println("Evaluated " + mf.totalNrMappedNodes+ " search nodes");
        ////        System.out.println("Found " + motifs.size() + " motifs, " + time_in_ms + " ms");
        //            printMotifs(motifs, output);

    }

}

From source file:Main.java

public static void main(String args[]) {
    String s = "java2s.com";
    int l;/*from  w  w  w.j a  v  a 2s .  co m*/
    l = s.length();
    for (int i = 0; i < l; i++) {
        int padding = s.length() - i;
        if (padding > 0) {
            System.out.printf("%" + padding + "s", " ");
        }
        for (int j = 0; j < i; j++) {
            System.out.printf("%c ", s.charAt(j));
        }
        System.out.printf("%c\n", s.charAt(i));
    }
}

From source file:mlbench.pagerank.PagerankMerge.java

@SuppressWarnings({ "rawtypes", "unchecked" })
public static void main(String[] args) throws IOException, InterruptedException {
    try {/*www .ja va  2  s  .  c  o m*/
        parseArgs(args);
        HashMap<String, String> conf = new HashMap<String, String>();
        initConf(conf);
        MPI_D.Init(args, MPI_D.Mode.Common, conf);

        JobConf jobConf = new JobConf(confPath);
        if (MPI_D.COMM_BIPARTITE_O != null) {
            // O communicator
            int rank = MPI_D.Comm_rank(MPI_D.COMM_BIPARTITE_O);
            int size = MPI_D.Comm_size(MPI_D.COMM_BIPARTITE_O);
            if (rank == 0) {
                LOG.info(PagerankMerge.class.getSimpleName() + " O start.");
            }
            FileSplit[] inputs = DataMPIUtil.HDFSDataLocalLocator.getTaskInputs(MPI_D.COMM_BIPARTITE_O, jobConf,
                    inDir, rank);
            for (int i = 0; i < inputs.length; i++) {
                FileSplit fsplit = inputs[i];
                LineRecordReader kvrr = new LineRecordReader(jobConf, fsplit);

                LongWritable key = kvrr.createKey();
                Text value = kvrr.createValue();
                {
                    while (kvrr.next(key, value)) {
                        String line_text = value.toString();
                        final String[] line = line_text.split("\t");
                        if (line.length >= 2) {
                            MPI_D.Send(new IntWritable(Integer.parseInt(line[0])), new Text(line[1]));
                        }
                    }
                }
            }

        } else if (MPI_D.COMM_BIPARTITE_A != null) {
            // A communicator
            int rank = MPI_D.Comm_rank(MPI_D.COMM_BIPARTITE_A);
            if (rank == 0) {
                LOG.info(PagerankMerge.class.getSimpleName() + " A start.");
            }
            HadoopWriter<IntWritable, Text> outrw = HadoopIOUtil.getNewWriter(jobConf, outDir,
                    IntWritable.class, Text.class, TextOutputFormat.class, null, rank, MPI_D.COMM_BIPARTITE_A);

            IntWritable oldKey = null;
            double next_rank = 0;
            double previous_rank = 0;
            double diff = 0;
            int local_diffs = 0;
            random_coeff = (1 - mixing_c) / (double) number_nodes;
            converge_threshold = ((double) 1.0 / (double) number_nodes) / 10;
            Object[] keyValue = MPI_D.Recv();
            while (keyValue != null) {
                IntWritable key = (IntWritable) keyValue[0];
                Text value = (Text) keyValue[1];
                if (oldKey == null) {
                    oldKey = key;
                }
                if (!key.equals(oldKey)) {
                    next_rank = next_rank * mixing_c + random_coeff;
                    outrw.write(oldKey, new Text("v" + next_rank));
                    diff = Math.abs(previous_rank - next_rank);
                    if (diff > converge_threshold) {
                        local_diffs += 1;
                    }
                    oldKey = key;
                    next_rank = 0;
                    previous_rank = 0;
                }

                String cur_value_str = value.toString();
                if (cur_value_str.charAt(0) == 's') {
                    previous_rank = Double.parseDouble(cur_value_str.substring(1));
                } else {
                    next_rank += Double.parseDouble(cur_value_str.substring(1));
                }

                keyValue = MPI_D.Recv();
            }
            if (previous_rank != 0) {
                next_rank = next_rank * mixing_c + random_coeff;
                outrw.write(oldKey, new Text("v" + next_rank));
                diff = Math.abs(previous_rank - next_rank);
                if (diff > converge_threshold)
                    local_diffs += 1;
            }
            outrw.close();
            reduceDiffs(local_diffs, rank);
        }

        MPI_D.Finalize();
    } catch (MPI_D_Exception e) {
        e.printStackTrace();
    }
}

From source file:POP3Demo.java

public static void main(String[] args) throws Exception {
    int POP3Port = 110;
    Socket client = new Socket("127.0.0.1", POP3Port);
    InputStream is = client.getInputStream();
    BufferedReader sockin = new BufferedReader(new InputStreamReader(is));
    OutputStream os = client.getOutputStream();
    PrintWriter sockout = new PrintWriter(os, true);
    String cmd = "user Smith";
    sockout.println(cmd);/*from  w w w.  j  av  a2s .  co  m*/
    String reply = sockin.readLine();
    cmd = "pass ";
    sockout.println(cmd + "popPassword");
    reply = sockin.readLine();
    cmd = "stat";
    sockout.println(cmd);
    reply = sockin.readLine();
    if (reply == null)
        return;
    cmd = "retr 1";
    sockout.println(cmd);
    if (cmd.toLowerCase().startsWith("retr") && reply.charAt(0) == '+')
        do {
            reply = sockin.readLine();
            System.out.println("S:" + reply);
            if (reply != null && reply.length() > 0)
                if (reply.charAt(0) == '.')
                    break;
        } while (true);
    cmd = "quit";
    sockout.println(cmd);
    client.close();
}