package org.example;
import java.nio.charset.Charset;
import java.util.*;
/**
* Hello world!
*
*/
public class App<T>
{
private static class A<T>{}
private static class B<T> extends A<T>{}
private A<T> [] en = new A[5];
public void aa() {
en[0] = new A<T>();
}
public static void main( String[] args ) throws Exception {
// String s = new String();//堆对象
// String s1= "";//字符串池 //字符串池对象
// System.out.println(s==s1);
//char [] c= {'a','b','c'};
// byte [] a= "abc".getBytes();
// String s = new String(a,"utf-8");
// System.out.println(s);
// String str="hello,world";
// String str1="hello,world..asdf";
// System.out.println(str.charAt(2));//根据下标提取对应字符
// System.out.println(str.codePointAt(2));//提取对应字符的ascii码
// //步骤
// // 1.测量两个字符串长度
// // 2.找到最小的字符串长度
// // 3.循环遍历所有字符找到第一个不同字符的位置
// // 4.用前字符-后字符
// //5.如果比较过程中一直都一样 就用户前字符串长度-后字符串长度
// //只有等于0说明两个字符串中的内容是一样的
// System.out.println(str.compareTo(str1));
// System.out.println(str.compareToIgnoreCase(str1));
// System.out.println(str.concat(str1));//把两个字符串连接在一起形成一个更大的字符串
// System.out.println(str1.contains(str));//查看是否包含 大小写区分
//
// String s1 = new String("abc");
// String s2 = String.copyValueOf(s1.toCharArray());//把字符串中的char数组复制一份 变成一个新的字符串
// String s3 = String.copyValueOf(s1.toCharArray(),1,2);//复制截断的功能 substring offset偏离量 count读取数量
// System.out.println(str1.endsWith("sdf"));//字符串是否以指定的字符序列结束
// System.out.println(s1 == s2);//1只比较对象地址是否一致
// System.out.println(s1.equals(s2));//1.先比较两个字符串地址是否一致 2.在两个字符串长度是否一致 3.比较每个字符是否相等
// System.out.println("abc".equalsIgnoreCase("Abc"));//忽略大小写
// System.out.println(String.format("你好,%s 你现在体温%f度","某某",36.5));//字符串模板 有许多的占位符
// //System.out.println("你好".getBytes().length);
// byte[] bytess = "中".getBytes();//将字符串转成byte数组 小心编码 //做转码
// String ss = new String(bytess,"utf-8");
// System.out.println(ss);
// //copy字符串中的数组
// char [] c = new char[5];
// "hello,cm".getChars(0,5,c,0);//字符串中截取你要的字符 并存放到指定的字符数组中//左包右不包
// System.out.println(new String(c));
// System.out.println("abc".hashCode());//获得一个hash值
// System.out.println("hello,world".indexOf("o",5));//从左向右搜索字符处在字符串什么位置 只返回匹配的第一个字符(串)的下标 找不到返回-1
// String e ="";
// System.out.println(e.isEmpty());//字符串中没有任何一个字符 就返回true (对象是否为空: e == null)
// System.out.println("hello,world".lastIndexOf("o"));//从右向左搜索字符处在字符串什么位置只返回匹配的第一个字符(串)的下标
// System.out.println("xxx".length());//测量字符串长度 字符串的length是方法
int [] aasa = new int[5];
aasa.length 数组中的length是属性
// String h1=",abc,hello,cde,";
// String h2="fgh,Hello,world";
// System.out.println(h1.regionMatches(false,4,h2,4,5));//是否忽略大小写 从什么地方开始比较 第2个字符串 第2字符串的偏离 字母个数
// System.out.println(h1.replace("l","y"));
// System.out.println(h1.split(",").length);
// String [] sps = h1.split(",",-1);//保证分割数据后所有的分割符两边都有值 如果一边没有字符 则使用""替代
// for (String sp:sps) {
// System.out.println(sp+"<==========>");
// }
// System.out.println(h1.startsWith(","));//字符串是否是按字符序列开头
// System.out.println(h1.substring(1,4));//截取字符串 左包右不包 h1.substring(5)==>从指定位置所有的都要
// System.out.println(h1.toCharArray());//将字符串转为字符数组
// System.out.println("Hello,World".toLowerCase());//将所有的字符都转为小写
// System.out.println("Hello,World".toUpperCase());//将所有的字符都转为大写
// System.out.println(h1);
// System.out.println(String.valueOf(1));
//变长的字符串
// StringBuffer sb = new StringBuffer();
// sb.append("hello,");
// sb.append("world");
// System.out.println(sb.capacity());//统计当前字符串底层数组的长度
// System.out.println(sb.toString().length());
// //System.out.println(sb.delete(5,7));//删除字符串中对应位置的子字符串
// //ystem.out.println(sb.deleteCharAt(5));
// // System.out.println(sb.insert(5,",xixi"));//在指定的位置上插入任意信息
// System.out.println(sb.reverse());//反转字符串
// sb.trimToSize();//将没有填写字符的空数组格去除 节约内存空间
// System.out.println(sb.capacity());
Map<String,String> map = new HashMap<String,String>();
map.put("123","asdf");
map.put("1234","asdf");
map.put("12345","asdf");
System.out.println(map.containsKey("123"));
}
}
String 和Stringbuffer一些常用方法
最新推荐文章于 2022-11-29 15:12:12 发布