package com.lovecoding.day17.ex01;

import org.junit.Test;

import java.util.Arrays;

public class Test01 {

    @Test
    public void test02(){
        //案例：有一个字符串String abc = “342567891”，请写程序将字符串abc进行升序，可以使用JDK API中的现有的功能方法。
        String abc = "342567891";
        //转换
        char[] chars = abc.toCharArray();

        //排序
        Arrays.sort(chars);

        System.out.println(Arrays.toString(chars));

    }

    @Test
    public void test01(){
        //定义数组，存入多个字符串。删除长度大于5的字符串，打印删除后的数组。
        String[] arr = {"heilongjiang","java","haerbin","c++","python","js","javascript"};
        /*
        {"heilongjiang","java","haerbin","c++","python","js","javascript"}
        {"java","haerbin","c++","python","js","javascript}
        {"java","haerbin","c++","python","js","javascript}
        {"java","c++","python","js","javascript}
        {"java","c++",,"js","javascript}
        {"java","c++",,"js"}
         */
        int count = arr.length;

        //循环
        for (int i = 0; i < count; i++) {
            if (arr[i].length()>5){
                //Params:
                //src – the source array.
                //srcPos – starting position in the source array.
                //dest – the destination array.
                //destPos – starting position in the destination data.
                //length – the number of array elements to be copied.
                System.arraycopy(arr,i+1,arr,i,count-1-i);
                i--;
                count--;
            }
        }

        String[] strings = Arrays.copyOf(arr, count);
        System.out.println(Arrays.toString(strings));

    }

}
