Main.java Source code

Java tutorial

Introduction

Here is the source code for Main.java

Source

//package com.java2s;
//License from project: Open Source License 

public class Main {
    public static String[] splitTitleAndContent(String src) {
        if (src == null) {
            throw new NullPointerException("Helper: splitTitleAndContent(src) - src cannot be null");
        }

        final int srcLength = src.length();
        String[] out = new String[2];

        int firstNewLinePosition = src.indexOf('\n');

        //the given String contains only one line
        if (firstNewLinePosition == -1) {
            out[0] = src;
            out[1] = "";
        } else {
            //extract the title
            out[0] = src.substring(0, firstNewLinePosition);
            //extract the content
            out[1] = src.substring(firstNewLinePosition + 1, srcLength);
        }

        return out;
    }
}