Main.java Source code

Java tutorial

Introduction

Here is the source code for Main.java

Source

//package com.java2s;

import java.util.ArrayList;

import java.util.List;

public class Main {
    private final static String INTEGER = "java.lang.Integer";
    private final static String LONG = "java.lang.Long";

    private static Object[] toArrayByString(String str) {
        List<Object> result = new ArrayList<Object>();
        str = str.substring(1, str.length() - 1);
        String type = str.substring(0, str.indexOf("@"));
        String[] values = str.substring(str.indexOf("@") + 1).split(",");
        for (int i = 0; i < values.length; i++) {
            String value = unesc(values[i]);
            if (LONG.equals(type)) {
                result.add(Long.valueOf(value));
            } else if (INTEGER.equals(type)) {
                result.add(Integer.valueOf(value));
            } else {
                result.add(value);
            }
        }
        return result.toArray();
    }

    private static String unesc(String str) {
        return str.replaceAll("&&&", ":").replaceAll("&!&", "[").replaceAll("!&!", "]").replaceAll("!!!", ",")
                .replaceAll("!!&", "{").replaceAll("&&!", "}").replaceAll("###", "@");
    }
}