- 博客(13)
- 收藏
- 关注
原创 反射
反射基本概念及使用方法:获取class对象的方式:1. Class.forName(“全类名”):将字节码文件加载进内存,返回class对象 多用于配置文件2.类名.class:通过类名的属性class获取 多用于参数的传递3.对象.getClass(): getclass()方法在object类中定义着。 多用于对象的获取字节码的方式代码体现:public static void main(String[] args) throws Exception {
2021-04-19 17:01:16
109
原创 Stream流
使用传统方式遍历集合public class p01List { public static void main(String[] args) { List<String> list = new ArrayList<>(); list.add("宋朋薇"); list.add("陈卓"); list.add("张顽强"); list.add("上官婉儿"); list.add("
2021-04-16 13:32:59
93
原创 Function接口练习
练习:自定义函数模型拼接题目:请使用Function进行函数模型的拼接,按照顺序需要执行的多个函数操作为:string str =“赵丽颖,20";分析:1.将字符串截取数字年龄部分,得到字符串;Function<string , string>“赵丽颖,20"->“20”2.将上一步的字符串转换成为int类型的数字;Function<string, Integer> “20”->203.将上一步的int数字累加100,得到结果int数字。Functi
2021-04-15 21:43:33
171
原创 Predicate接口基本使用
/*java.util.function . Predicate接口作用:对某种数据类型的数据进行判断,结果返回一个boolean值Predicate接口中包含一个抽象方法:boolean test(T t):用来对指定数据类型数据进行判断的方法结果:符合条件,返回true不符合条件,返回falsepublic class p01Predicate { /* 定义一个方法 参数传递一个string类型的字符串 传递一个Predicate接口,泛型使用strin
2021-04-15 17:49:04
1786
原创 Consumer接口基本使用
/*java.util.function.Consumer接口则正好与supplier接口相反,它不是生产一个数据,而是消费一个数据,其数据类型由泛型决定。Consumer接口中包含抽象方法void accept(T t),意为消费一个指定泛型的数据。Consumer接口是一个消费型接口,泛型执行什么类型,就可以使用accept方法消费什么类型的数据至于具体怎么消费(使用)需要自定义(输出,计算…)*/public class p01Consumer { /*定义一个方法 方法的参
2021-04-14 20:23:11
1065
原创 函数式接口案例
如果一个方法的返回值类型是一个函数式接口,那么就可以直接返回一个Lambda表达式。当需要通过一个方法来获取一个java.util.Comparator接口类型的对象作为排序器时,就可以调该方法获取。public class p01Comparator { //定义一个方法,方法的返回值类型使用函数式接口Comparator public static Comparator<String> getComparator(){ //方法的返回值类型是一个接口,那么
2021-04-14 16:47:11
192
原创 文件上传案例的代码实现
客户端代码:public class p01TCPClient { public static void main(String[] args) throws IOException { FileInputStream fis = new FileInputStream("D:\\psq\\shiyan\\lianxi\\java\\aa.txt"); Socket socket = new Socket("127.0.0.1",8888); O
2021-04-11 18:04:57
84
原创 TCP通信的代码实现
TCP通信的客户端代码实现代码:public class TCPClient { public static void main(String[] args) throws IOException { Socket socket = new Socket("127.0.0.1",8888); OutputStream os = socket.getOutputStream(); os.write("你好服务器".getBytes());
2021-04-11 17:05:55
194
原创 斗地主案例
斗地主案例实现public class DouDiZhu {public static void main(String[] args) { ArrayList<String> poker = new ArrayList<>(); String[] colors = {"♠","♥","♣","♦"}; String[] nums = {"2","A","k","j","q","3","4","5","6","7","8","9","10"};
2021-03-24 16:31:54
53
原创 静态static
静态static关键字修饰成员方法public static void main(String[] args) { //首先设置教室,这是静态的东西,应该通过类名称进行调用 Student.room = "101教室"; Student one = new Student("贾乃亮",38); System.out.println("年龄:"+ one.getAge()); System.out.println(
2021-03-09 11:02:40
54
原创 String练习题
public static void main(String[] args) { int [] array = {1,2,3,4}; String result = fromArratToString(array); System.out.println(result);}public static String fromArratToString(int[]array){ String str = "["; for (int i = 0; i < ar.
2021-03-08 17:45:11
100
1
原创 3.6字符串的构造和直接创建
public static void main(String[] args) { // 空参构造 String str1 = new String(); System.out.println("第一个字符串:" +str1); //根据字符串数组创建字符串 char[] charArray = {'A','B','C'}; String str2 = new String(charArray); System.out.println(.
2021-03-08 10:56:49
92
原创 ArrayList习题
public static void main(String[] args) { ArrayList<String> list = new ArrayList<>(); list.add("杨幂"); list.add("迪丽热巴"); list.add("王冰冰"); System.out.println(list); printArrayList(list);}public static void printArrayL.
2021-03-07 15:28:18
280
空空如也
空空如也
TA创建的收藏夹 TA关注的收藏夹
TA关注的人