Java如何输入不确定长度的数组

public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        List list=new ArrayList();
        while (in.hasNext()) {
            String s=in.nextLine();

            String[] str=s.split(" ");  
            int[] a=new int[str.length];
            for(int i=0;i

数组排序和去重

  Arrays.sort(A);
       List list=new ArrayList();
       //数组去重
       for(int i=0;iif(A[i]>0&&!list.contains(A[i])){
               list.add(A[i]);
               System.out.print(A[i]+" ");
           }
       }
public static boolean isHuiWen(String text) {
        int length = text.length();
        for (int i = 0; i < length / 2; i++) {
            if (text.toCharArray()[i] != text.toCharArray()[length - i - 1]) {
                return false;
            }
        }
        return true;
    }

你可能感兴趣的:(数据结构与算法,java,string,arraylist)