提交 a027e42d 编写于 作者: X xiaoyu

add files

上级 74fe4937
package com.example.demo.bo;
import lombok.Data;
@Data
public class UserBo {
private int id;
private String name;
}
...@@ -6,10 +6,6 @@ import org.springframework.web.bind.annotation.RestController; ...@@ -6,10 +6,6 @@ import org.springframework.web.bind.annotation.RestController;
import java.util.List; import java.util.List;
/**
* @author lixiaoyu
* @since 2:16 下午
*/
@RestController @RestController
@RequestMapping("/") @RequestMapping("/")
public class BaseController { public class BaseController {
......
package com.example.demo.controller;
import com.example.demo.bo.UserBo;
import com.example.demo.tool.Gengric;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import java.util.*;
@RestController
@RequestMapping("/")
public class StringController {
@GetMapping("/string")
public void stringDemo(){
//字符
char charDemo1 = 'x';
Character charDemo2 = new Character('x');
//字符串
String stringDemo1 = "test";
String stringDemo2 = new String("test");
stringDemo2.length(); //获取长度
stringDemo2.concat(" user"); //拼接字符串
stringDemo2.toLowerCase(); //转小写
stringDemo2.compareTo(stringDemo1); //对比
stringDemo2.substring(1,3); //截取
//字符串缓冲区
StringBuffer stringDemo3 = new StringBuffer("test");
stringDemo3.append(" user"); //追加
stringDemo3.insert(2,"u"); //插入
stringDemo3.delete(2,3); //删除
stringDemo3.length(); //获取长度
stringDemo3.substring(0,2); //截取
}
@GetMapping("/array")
public void arrayDemo(){
//数组,必须指定大小
String[] arrDemo1 = new String[3];
arrDemo1[0] = "str1";
arrDemo1[1] = "str1"; //值可以重复
arrDemo1[2] = "str1";
String[] arrDemo2 = arrDemo1.clone(); //复制 克隆
Arrays.fill(arrDemo2,"test2"); //Array类的使用
UserBo[] arrDemo3 = new UserBo[5]; //对象数组,不是只能用基本类型
}
@GetMapping("/arraylist")
public void arraylistDemo(){
//泛型可以接收任何参数
Gengric<String> aDemo1 =new Gengric<>();
aDemo1.setDemo1("string");
//不只是基本数据类型
Gengric<UserBo> aDemo2 =new Gengric<>();
UserBo userBo = new UserBo();
aDemo2.setDemo1(userBo);
//单向链表
LinkedList<String> aDemo3 = new LinkedList<>();
aDemo3.add("str1"); //插入
aDemo3.get(0); //获取
aDemo3.addFirst("str2"); //头部添加
aDemo3.addLast("str3"); //尾部添加
aDemo3.size(); //长度
//动态数组
ArrayList aDemo4 = new ArrayList<>();
aDemo4.add(userBo);
aDemo4.add("str5");
aDemo4.add(100); //可以加入不同数据类型
//HashSet
HashSet<Integer> aDemo5 = new HashSet<>();
aDemo5.add(1);
aDemo5.add(2);
//TreeSet
TreeSet<Integer> aDemo6 = new TreeSet<>();
aDemo6.add(20);
aDemo6.add(10);
aDemo6.add(50);
//HashMap
HashMap<Integer,String> aDemo7 = new HashMap<>();
aDemo7.put(5,"str8");
aDemo7.put(1,"str9");
aDemo7.put(3,"str10");
//TreeMap
TreeMap<Integer,String> aDemo8 = new TreeMap<>();
aDemo8.put(5,"str8");
aDemo8.put(1,"str9");
aDemo8.put(3,"str10");
}
}
package com.example.demo.tool;
/**
* 泛型的类
* @param <T>
*/
public class Gengric<T> {
private T demo1;
public void setDemo1(T demo1){
this.demo1 = demo1;
}
public T getDemo1(){
return this.demo1;
}
}
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册