从2个已知数组中初始化新数组

时间:2016-07-10 14:00:38

标签: java arrays initialization

如何从已知数组中初始化新数组?

e.g。

char[] word1 = new char[]{'H', 'e', 'l', 'l', 'o'};
char[] word2 = new char[]{'W', 'o', 'r', 'l', 'd'};
char[] newArray;

那么如何从word1和word2初始化newArray?

感谢。

2 个答案:

答案 0 :(得分:1)

创建新数组并使用System.arraycopy()复制值。

    private static List<List<Object>> buildRows(Fusiontables db, Set<String> rowIds, List<List<Object>> allRows)
        throws Exception {
    BatchRequest batchRequest = db.batch();
    int c = 1;
    BatchCallback<Sqlresponse, GoogleJsonErrorContainer> batchCallback = getBatchCallback(allRows);

    for (String id : rowIds) {
        String sqlQuery = "SELECT * FROM " + TABLE_ID + " WHERE ROWID = '" + id + "'";

        HttpRequest request = db.query().sqlGet(sqlQuery).buildHttpRequest();
        batchRequest.queue(request, Sqlresponse.class, GoogleJsonErrorContainer.class, batchCallback);

        c++;
        if (c == 200) {
            batchRequest.execute();
            Thread.sleep(REQUEST_QUOTAS_LIMIT);
        }
    }

    private static BatchCallback<Sqlresponse, GoogleJsonErrorContainer> getBatchCallback(final List<List<Object>> out) {
    return new BatchCallback<Sqlresponse, GoogleJsonErrorContainer>() {
        @Override
        public void onSuccess(Sqlresponse sqlresponse, HttpHeaders httpHeaders) throws IOException {
            out.addAll(sqlresponse.getRows());
        }
        @Override
        public void onFailure(GoogleJsonErrorContainer googleJsonErrorContainer, HttpHeaders httpHeaders) throws IOException {
            System.err.println("Batching fails");
            System.err.println(googleJsonErrorContainer.getError());
        }
    };
}

答案 1 :(得分:0)

使用此代码初始化newArray:

"true"

这应该这样做。