zoukankan      html  css  js  c++  java
  • JAVA数组

    public class Main {
        public static void main(String[] args) {
            // char a[][]={{"ff"},{"ee"}};
            char c[][] = { { 'a', 'c' }, { 'c', 'd' } };
            String[][] list = { { "1", "张三" }, { "2", "李四" }, { "3", "王五" } };
            for (int i = 0; i < c.length; i++) {
                for (int j = 0; j < c[0].length; j++) {
                    System.out.println(c[i][j]);
                }
            }
            System.out.println("..............");
            for (int i = 0; i < list.length; i++) {
                for (int j = 0; j < list[0].length; j++) {
                    System.out.println(list[i][j]);
                }
            }
        }
    
    }
    public class Main {
        public static void main(String[] args) {
            // char a[][]={{"ff"},{"ee"}};
            char c[][] = new char[3][4];
            String[] list = { "1230", "ewfr", "sddf" };
            for (int i = 0; i < 3; i++) {
                for (int j = 0; j < 4; j++) {
                    c[i][j] = list[i].charAt(j);
                }
            }
            for (int i = 0; i < 3; i++) {
                for (int j = 0; j < 4; j++) {
                    System.out.println(c[i][j]);
                }
            }
    
        }
    }

    binarySearch()方法

    https://blog.csdn.net/qpzkobe/article/details/78897762

     binarySearch(Object[], Object key)

    a: 要搜索的数组

    key:要搜索的值

    如果key在数组中,则返回搜索值的索引

    import java.util.*;
    
    public class Main {
        public static void main(String[] args) throws Exception {
            Map<String, Integer> map = new HashMap<>();
    
            int nums[] = { 1, 2, 4, 8 };
            int index1 = Arrays.binarySearch(nums, 2);
            int index2 = Arrays.binarySearch(nums, 0);
            int index3 = Arrays.binarySearch(nums, 9);
            int index4 = Arrays.binarySearch(nums, 6);
            System.out.println("2: " + index1 + " 0: " + index2 + " 9: " + index3 + " 6: " + index4);
    
        }
    }

    System.arrayCopy

    https://blog.csdn.net/qq_32405269/article/details/78374035

    public static void arraycopy(Object src, int srcPos, Object dest, int destPos, int length)
    代码解释:
      Object src : 原数组
    int srcPos : 从元数据的起始位置开始
      Object dest : 目标数组
      int destPos : 目标数组的开始起始位置
      int length : 要copy的数组的长度
    Arrays.copyOfRange
     return Arrays.copyOfRange(a,0,cnt);//返回数组a【0,cnt)
    Arrays.asList
    https://blog.csdn.net/weixin_42585968/article/details/107465070
    将数组转化为list
    数组去重
       static public String[] qu(String[] a) {
            int cnt = 0;
            Set set = new HashSet<>();
            for (String x : a) {
                set.add(x);
            }
            Object[] ob = set.toArray();
            for (Object x : ob) {
                a[cnt++] = (String) x;
            }
            return Arrays.copyOfRange(a, 0, cnt);
        }
     
     
  • 相关阅读:
    中缀表达式std
    后缀表达式
    取石头游戏
    LeetCode404Sum of Left Leaves左叶子之和
    LeetCode387First Unique Character in a String字符串中第一个唯一字符
    简单排列习题2.5 的 2
    周期串Uva455 P37 3-4
    【递归】分形
    【递归】普通递归关系(矩阵快速幂)
    P3486 [POI2009]KON-Ticket Inspector
  • 原文地址:https://www.cnblogs.com/tingtin/p/15724798.html
Copyright © 2011-2022 走看看