zoukankan      html  css  js  c++  java
  • 基础笔记3(一)(String StringBuilder StringBuffer 数组)

    ---恢复内容开始---

    1数组.有序的同类型的集合。

    2.string :字符串类型:其实就是一个字符数组。添加了private final,所以string是一个不可以变的字符串。

    String.charAt(index):或者字符数组的元素

    equals():比较是每个字符是否相等。即比较的是内容。

    字符串常用方法和源码;

    3.stringbuilder

     可扩容的字符串。也就是自动实现了字符数组的扩大。一般是两倍。

     4,arraylist。数组列表,封装了数组。

    5.多维数组:

    虽然数组定义时候要声明长度,但对于多维数组,声明第一维就可以了。(多维数组看成是在一维数组中加入其他维度的数组)

    int[][] a=new int[3][];
    a[0]=new int[3];
    a[1]=new int[5];
    ....
    a[0][0]=1;
    a[0][1]=3;
    ....
    //二维数组长度可以随意,
    

    6,system.arraycopy(Object src, int srcPos, Object dest, int destPos, int length)

       @param src the source array.
    * @param srcPos starting position in the source array.
    * @param dest the destination array.
    * @param destPos starting position in the destination data.
    * @param length the number of array elements to be copied.

    将一个数组复制到另一个数组中

    arrays类中copyOf方法也是调用。  

     public static char[] copyOf(char[] original, int newLength) {
            char[] copy = new char[newLength];
            System.arraycopy(original, 0, copy, 0,
                             Math.min(original.length, newLength));//这样做有一定的容错能力,不用考虑越界了
            return copy;
        }
    

    8.Arrays类提供一些处理数组的方法。(常用的排序和查找方法

    sort(基本类型数组):排序。

    binarySeach(数组,元素)。二分法查找。必须先排序。

    toStirng(数组对象):数组元素的打印效果

    fill(int[] a, int fromIndex, int toIndex, int val):将数组索引从...到...替换成。

    9.如果是对象数组排序。对象需要实现comparable接口的compareTo方法。

    10冒泡法:

    int[] a = {...};
    		for (int i = 0; i < a.length - 1; i++) {
    			for (int j = 0; j < a.length - 1 - i; j++) {
    				if (a[j] > a[j + 1]) {
    					int t = a[j];
    					a[j] = a[j + 1];
    					a[j + 1] = t;
    				}
    			}
    		}
    		System.out.println(Arrays.toString(a));
    

      

  • 相关阅读:
    HDOJ 1588 Gauss Fibonacci
    HDOJ 1494 跑跑卡丁车
    初识Linux
    大数据教程
    80后上班族
    人际交往,七种心态最惹人讨厌
    商人初步
    分页存储过程
    父母生日
    dephi小技巧
  • 原文地址:https://www.cnblogs.com/straybirds/p/6059750.html
Copyright © 2011-2022 走看看