集册 Java实例教程 从位置pos切数组。

从位置pos切数组。

欢马劈雪     最近更新时间:2020-01-02 10:19:05

411
提示:您可在线编辑运行本教程的实例 - 运行实例,去试试!
从位置pos切数组。

/*

 This file is part of p300.



 p300 is free software: you can redistribute it and/or modify

 it under the terms of the GNU General Public License as published by

 the Free Software Foundation, either version 3 of the License, or

 (at your option) any later version.


 p300 is distributed in the hope that it will be useful,

 but WITHOUT ANY WARRANTY; without even the implied warranty of

 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the

 GNU General Public License for more details.


 You should have received a copy of the GNU General Public License

 along with p300.  If not, see <http://www.gnu.org/licenses/>.

 */

//package com.nowjava;//来 自 nowjava.com - 时代Java


public class Main {

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

        byte[] b = new byte[] { 34, 35, 36, 37, 37, 37, 67, 68, 69 };

        int pos = 2;

        System.out.println(java.util.Arrays.toString(cutAt(b, pos)));

    }


    /**

     * Cut the arrays from position pos.

     * Won't change the original array.

     * @param b

     * @param pos

     * @return Copy of the array, only between pos and end

     */

    public static byte[] cutAt(byte[] b, int pos) {

        if (b == null || pos <= 0) {

            return b;

        }

        if (pos >= b.length) {

            return new byte[0];

        }

      
展开阅读全文