Example usage for java.lang String concat

List of usage examples for java.lang String concat

Introduction

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

Prototype

public String concat(String str) 

Source Link

Document

Concatenates the specified string to the end of this string.

Usage

From source file:Main.java

public static void main(String[] argv) {
    String str = "java2s.com";

    str = str.concat(" Java2s.com");
    System.out.println(str);/*ww w  .  j a v a  2  s. c  om*/
}

From source file:MainClass.java

public static void main(String args[]) {
    String s1 = new String("Happy ");
    String s2 = new String("Birthday");

    System.out.printf("s1 = %s\ns2 = %s\n\n", s1, s2);
    System.out.printf("Result of s1.concat( s2 ) = %s\n", s1.concat(s2));
    System.out.printf("s1 after concatenation = %s\n", s1);
}

From source file:org.eclipse.swt.snippets.Snippet268.java

public static void main(String[] args) {
    final Display display = new Display();
    Shell shell = new Shell(display);
    shell.setText("Snippet 268");
    shell.setLayout(new FillLayout());
    StyledText styledText = new StyledText(shell, SWT.V_SCROLL);
    String multiLineString = "";
    for (int i = 0; i < 200; i++) {
        multiLineString = multiLineString.concat("This is line number " + i + " in the multi-line string.\n");
    }/*from w  w  w .ja  v a  2 s.c o m*/
    styledText.setText(multiLineString);
    shell.setSize(styledText.computeSize(SWT.DEFAULT, 400));
    shell.open();
    // move cursor over styled text
    Rectangle clientArea = shell.getClientArea();
    Point location = shell.getLocation();
    Event event = new Event();
    event.type = SWT.MouseMove;
    event.x = location.x + clientArea.width / 2;
    event.y = location.y + clientArea.height / 2;
    display.post(event);
    styledText.addListener(SWT.MouseWheel, e -> System.out.println("Mouse Wheel event " + e));
    new Thread() {
        Event event;

        @Override
        public void run() {
            for (int i = 0; i < 50; i++) {
                event = new Event();
                event.type = SWT.MouseWheel;
                event.detail = SWT.SCROLL_LINE;
                event.count = -2;
                if (!display.isDisposed())
                    display.post(event);
                try {
                    Thread.sleep(100);
                } catch (InterruptedException e) {
                }
            }
        }
    }.start();
    while (!shell.isDisposed()) {
        if (!display.readAndDispatch())
            display.sleep();
    }
    display.dispose();
}

From source file:Main.java

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

    SimpleDateFormat sdf = new SimpleDateFormat("MM/dd/yyyy");

    String oeStartDateStr = "04/01/2015";
    String oeEndDateStr = "11/14/2015";

    Calendar cal = Calendar.getInstance();
    Integer year = cal.get(Calendar.YEAR);

    oeStartDateStr = oeStartDateStr.concat(year.toString());
    oeEndDateStr = oeEndDateStr.concat(year.toString());

    Date startDate = sdf.parse(oeStartDateStr);
    Date endDate = sdf.parse(oeEndDateStr);
    Date d = new Date();
    String currDt = sdf.format(d);

    if ((d.after(startDate) && (d.before(endDate)))
            || (currDt.equals(sdf.format(startDate)) || currDt.equals(sdf.format(endDate)))) {
        System.out.println("Date is between 1st april to 14th nov...");
    } else {/* w  w  w  .  ja  v  a2 s .  com*/
        System.out.println("Date is not between 1st april to 14th nov...");
    }
}

From source file:de.uni_potsdam.hpi.bpt.promnicat.importer.ModelImporter.java

/**
 * Usage: <code>'Path to config' Collection PATH [PATH2 [PATH3] ...]]</code>
 * </br></br>//w  w w  .  j  av a2  s  .c  o  m
 * <code>Path to config</code> is a path in file system to the configuration file being used
 * for import. It can be given relative to the PromniCAT folder.</br>
 * If an empty string is provided, the default file 'PromniCAT/configuration.properties' is used.</br></br>
 * <code>Collection</code> is the process model collection and can be one of
 * 'BPMN', 'NPB', 'SAP_RM' or 'AOK' </br></br>
 * <code>PATH</code> is a path in file system to a directory containing the models that should be imported.
 */
public static void main(String[] args) {

    // wrong number of parameter?
    if (args.length < 3) {
        printHelpMessage();
        return;
    }

    try {
        //read configuration file
        IPersistenceApi persistenceApi = new ConfigurationParser(args[0])
                .getDbInstance(Constants.DATABASE_TYPES.ORIENT_DB);

        //import models         
        // BPMAI model?
        if (args[1].toUpperCase().equals(Constants.ORIGIN_BPMAI)) {
            startImport(new BpmaiImporter(persistenceApi), args);
            return;
        }
        // NPB model?
        if (args[1].toUpperCase().equals(Constants.ORIGIN_NPB)) {
            startImport(new NPBImporter(persistenceApi), args);
            return;
        }
        // SAP_RM model?
        if (args[1].toUpperCase().equals(Constants.ORIGIN_SAP_RM)) {
            startImport(new SapReferenceModelImporter(persistenceApi), args);
            return;
        }
        // AOK model?
        if (args[1].toUpperCase().equals(Constants.ORIGIN_AOK)) {
            startImport(new AokModelImporter(persistenceApi), args);
            return;
        }
        // wrong argument value
        printHelpMessage();
        throw new IllegalArgumentException(WRONG_USAGE_MESSAGE);
    } catch (Exception e) {
        logger.severe(e.getMessage());
        String stackTraceString = "";
        for (StackTraceElement ste : e.getStackTrace()) {
            stackTraceString = stackTraceString.concat(ste.toString() + "\n");
        }
        logger.severe(stackTraceString);
    }
}

From source file:com.github.cereda.sucuri.Sucuri.java

/**
 * Main method./*from ww  w .  ja  v a 2  s  .  c om*/
 * 
 * @param args The command line arguments.
 */
public static void main(String[] args) {
    try {

        // draw header
        SucuriUtils.drawHeader();

        // provide the command line arguments
        CommandLineAnalyzer cmd = new CommandLineAnalyzer(args);

        // try to parse them
        if (cmd.parse()) {

            // get the template
            LanguageFile template = new LanguageFile();
            template.load(cmd.getTemplate());

            // get the input
            LanguageFile input = new LanguageFile();
            input.load(cmd.getInput(), cmd.getEncoding());

            // set the output
            LanguageFile output = new LanguageFile();

            // get the differences
            List<String> newKeysOnTemplate = (List<String>) CollectionUtils.subtract(template.getKeys(),
                    input.getKeys());
            List<String> oldKeysOnInput = (List<String>) CollectionUtils.subtract(input.getKeys(),
                    template.getKeys());

            // check for report
            if (cmd.hasReport()) {

                // add new info
                Report report = new Report(cmd.getOutput().getName().concat(".txt"));
                report.generate(cmd.getTemplate().getName(), cmd.getInput().getName(),
                        cmd.getOutput().getName(), newKeysOnTemplate, oldKeysOnInput);
            }

            // set header
            String header = "Converted from '" + cmd.getTemplate().getName() + "' and '" + cmd.getInput()
                    + "'\n";
            header = header.concat("by sucuri ").concat(SucuriConstants.VERSION).concat(" on ")
                    .concat(SucuriUtils.getDate());
            output.setHeader(header);

            // sets
            Set<String> keysTemplate = template.getKeys();
            Set<String> keysInput = input.getKeys();

            // iterate
            for (String key : keysTemplate) {

                // if it's a new key
                if (!keysInput.contains(key)) {

                    // set from template
                    output.setProperty(key, template.getProperty(key));
                } else {

                    // set from input
                    output.setProperty(key, input.getProperty(key));
                }
            }

            // save new output
            output.save(cmd.getOutput());

            // print message
            System.out.println("File converted successfully.");

        }
    } catch (SucuriException sucuriException) {

        // an error ocurred, print it
        System.out.println("\n".concat(sucuriException.getMessage()));
    }
}

From source file:net.kolola.msgparsercli.MsgParseCLI.java

public static void main(String[] args) {

    // Parse options

    OptionParser parser = new OptionParser("f:a:bi?*");
    OptionSet options = parser.parse(args);

    // Get the filename
    if (!options.has("f")) {
        System.err.print("Specify a msg file with the -f option");
        System.exit(0);/*  www .jav a  2s .co m*/
    }

    File file = new File((String) options.valueOf("f"));

    MsgParser msgp = new MsgParser();
    Message msg = null;

    try {
        msg = msgp.parseMsg(file);
    } catch (UnsupportedOperationException | IOException e) {
        System.err.print("File does not exist or is not a valid msg file");
        //e.printStackTrace();
        System.exit(1);
    }

    // Show info (as JSON)
    if (options.has("i")) {
        Map<String, Object> data = new HashMap<String, Object>();

        String date;

        try {
            Date st = msg.getClientSubmitTime();
            date = st.toString();
        } catch (Exception g) {
            try {
                date = msg.getDate().toString();
            } catch (Exception e) {
                date = "[UNAVAILABLE]";
            }
        }

        data.put("date", date);
        data.put("subject", msg.getSubject());
        data.put("from", "\"" + msg.getFromName() + "\" <" + msg.getFromEmail() + ">");
        data.put("to", "\"" + msg.getToRecipient().toString());

        String cc = "";
        for (RecipientEntry r : msg.getCcRecipients()) {
            if (cc.length() > 0)
                cc.concat("; ");

            cc.concat(r.toString());
        }

        data.put("cc", cc);

        data.put("body_html", msg.getBodyHTML());
        data.put("body_rtf", msg.getBodyRTF());
        data.put("body_text", msg.getBodyText());

        // Attachments
        List<Map<String, String>> atts = new ArrayList<Map<String, String>>();
        for (Attachment a : msg.getAttachments()) {
            HashMap<String, String> info = new HashMap<String, String>();

            if (a instanceof FileAttachment) {
                FileAttachment fa = (FileAttachment) a;

                info.put("type", "file");
                info.put("filename", fa.getFilename());
                info.put("size", Long.toString(fa.getSize()));
            } else {
                info.put("type", "message");
            }

            atts.add(info);
        }

        data.put("attachments", atts);

        JSONObject json = new JSONObject(data);

        try {
            System.out.print(json.toString(4));
        } catch (JSONException e) {
            e.printStackTrace();
        }
    }

    // OR return an attachment in BASE64
    else if (options.has("a")) {
        Integer anum = Integer.parseInt((String) options.valueOf("a"));

        Encoder b64 = Base64.getEncoder();

        List<Attachment> atts = msg.getAttachments();

        if (atts.size() <= anum) {
            System.out.print("Attachment " + anum.toString() + " does not exist");
        }

        Attachment att = atts.get(anum);

        if (att instanceof FileAttachment) {
            FileAttachment fatt = (FileAttachment) att;
            System.out.print(b64.encodeToString(fatt.getData()));
        } else {
            System.err.print("Attachment " + anum.toString() + " is a message - That's not implemented yet :(");
        }
    }
    // OR print the message body
    else if (options.has("b")) {
        System.out.print(msg.getConvertedBodyHTML());
    } else {
        System.err.print(
                "Specify either -i to return msg information or -a <num> to print an attachment as a BASE64 string");
    }

}

From source file:Jpeg.java

public static void main(String args[]) {
    Image image = null;//ww  w  . j  av  a  2 s.c  om
    FileOutputStream dataOut = null;
    File file, outFile;
    JpegEncoder jpg;
    String string = "";
    int i, Quality = 80;
    // Check to see if the input file name has one of the extensions:
    // .tif, .gif, .jpg
    // If not, print the standard use info.
    if (args.length < 2)
        StandardUsage();
    if (!args[0].endsWith(".jpg") && !args[0].endsWith(".tif") && !args[0].endsWith(".gif"))
        StandardUsage();
    // First check to see if there is an OutputFile argument. If there isn't
    // then name the file "InputFile".jpg
    // Second check to see if the .jpg extension is on the OutputFile argument.
    // If there isn't one, add it.
    // Need to check for the existence of the output file. If it exists already,
    // rename the file with a # after the file name, then the .jpg extension.
    if (args.length < 3) {
        string = args[0].substring(0, args[0].lastIndexOf(".")) + ".jpg";
    } else {
        string = args[2];
        if (string.endsWith(".tif") || string.endsWith(".gif"))
            string = string.substring(0, string.lastIndexOf("."));
        if (!string.endsWith(".jpg"))
            string = string.concat(".jpg");
    }
    outFile = new File(string);
    i = 1;
    while (outFile.exists()) {
        outFile = new File(string.substring(0, string.lastIndexOf(".")) + (i++) + ".jpg");
        if (i > 100)
            System.exit(0);
    }
    file = new File(args[0]);
    if (file.exists()) {
        try {
            dataOut = new FileOutputStream(outFile);
        } catch (IOException e) {
        }
        try {
            Quality = Integer.parseInt(args[1]);
        } catch (NumberFormatException e) {
            StandardUsage();
        }
        image = Toolkit.getDefaultToolkit().getImage(args[0]);
        jpg = new JpegEncoder(image, Quality, dataOut);
        jpg.Compress();
        try {
            dataOut.close();
        } catch (IOException e) {
        }
    } else {
        System.out.println("I couldn't find " + args[0] + ". Is it in another directory?");
    }
    System.exit(0);
}

From source file:Main.java

public static String concat(String arg1, String arg2) {
    return arg1.concat(arg2);
}

From source file:Main.java

public static void call(Context cxt, String number) {
    String phoneUri = "tel:";
    phoneUri = phoneUri.concat(number);
    Intent intent = new Intent(Intent.ACTION_CALL, Uri.parse(phoneUri));
    cxt.startActivity(intent);/*from  w w w. j ava 2  s. c o  m*/
}