Java常用类学习笔记

Arrays类

–equals 方法
比较两个数组对象中元素是否相等.
而数组对象中的equals用来判断与另一个数组对象是否相等。
声明:public static boolean equals(type[]a,type[]a2)
参数的类型可以是原生数据类型和引用类型的任意一种类型
返回:如果两个相等,则返回true,否则返回false

–sort -排序
作用于数组的所有元素
public static void sort(type[] a)
作用于数组指定范围内的元素
public static void sort(type[] a, int fromIndex(包括), int toIndex(不包括))
将指定的类型数组所有元素按数字升序进行排序

–binarySearch

使用二分搜索算法搜索指定数组
public static int binarySearch(type[] a, type key)
public static int binarySearch(long[] a,int fromIndex,int
toIndex,long key)

参数:
a - 要搜索的数组。
key - 要搜索的值。
fromIndex - 要排序的第一个元素的索引(包括)。
toIndex - 要排序的最后一个元素的索引(不包括)

–copyOf方法
数组复制,将指定数组中的元素复制到一个指定长度的新数组中,并返回
新数组.
static int[] copyOf(int[] a, int newLength)
–fill方法
将指定的int值分配给指定的int数组的每个元素。
fill(int[] a, int val)

–toString() 方法
public static String toString(type[] a)
返回指定数组内容的字符串表示形式

以Integer为例的基本数据类型

静态方法

public static final int MAX_VALUE 最大的int型数(231-1)
public static final int MIN_VALUE 最小的int型数(-231)

构造方法
Integer(int a);
Integer(String a);------字符串必须是纯数字字符串
比较方法

均为比较大小的方法

static int compareTo(Integer a);
boolean equals(Object);
int max(int a,int b);
int min(int a,int b);

转换方法
static toBinaryString(int i);
static String toHexString(int i);
static String toOctalString(int i);
int intValue();
static int parseInt(String s);
String toString();
static Integer valueOf(int i)
static Integer valueOf(String s)

String类

构造方法
public String()
public String(String str)
public String(byte[] bytes)
public String(char[] value)

//分为有参和无参

判断功能
boolean equals(Object obj)
boolean equalsIgnoreCase(String str)
boolean contains(String str)
boolean isEmpty()
boolean startsWith(String prefix)
boolean endsWith(String suffix)

获取功能
int length()

//获取长度

char charAt(int index)

//获取位置

int indexOf(String str)
int indexOf(String str,int fromIndex)

//获取位置,可定义起始位置

String substring(int start)
String substring(int start,int end)

// 截取

转换功能
byte[] getBytes()
char[] toCharArray()

//转为对应类型的数组
String toLowerCase()
String toUpperCase()

//改变大小写

String concat(String str)
Stirng[] split(分割符);

// 分割数组

替换功能
String replace(char old,char new)
String replace(String old,String new)

// 替换所有的指定内容的字符/字符串为新内容

replaceAll(String regex, String replacement)
replaceFirst(String regex, String replacement)

//替换第一个指定内容出现时对应的字符/字符串为新内容

去除字符串两空格
String trim()

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 1
    评论
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

Aceti_c张晨

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值