Java
请叫我王小二
这个作者很懒,什么都没留下…
展开
-
把一个数分解成任意几个数之和
例如:4的结果有,(1+3),(2+2),(1+1+2),(1+1+1+1)public class Demo { // 存储每次分割的值 static int[] arr; // 需要分割的值 static int num = 4; public static void main(String[] args) { // 分割的值最多分成1+1+...+1 最多就是他本身的长度 arr = new int[num];原创 2020-05-14 18:07:42 · 4637 阅读 · 0 评论 -
SpringBoot的junit测试用例
以下是关于SpringBoot的junit测试用例,有关Controller层测试以及Service层、Dao层测试都适用。首先pom文件中需要增加 spring-boot-starter-test 包,且junit的版本为4.0以后版本。 <dependency> <groupId>junit</groupId> ...原创 2020-03-31 16:03:58 · 834 阅读 · 0 评论 -
JAVA中循环删除list中元素的方法
iterator遍历(这是最好的,最正常的)Iterator<String> it = list.iterator();while(it.hasNext()){ String x = it.next(); if(x.equals("del")){ it.remove(); }}这种方式可以正常的循环及删除。但要注意的是,要使用ite...转载 2018-07-24 17:05:34 · 199 阅读 · 0 评论 -
java判断集合list是否为空
方法有二:其一为:if(list!=null && list.size()>=0){//判断list是否为空,且list集合中包含的元素个数小于等于0个}其二为:这是最常用的方法,简单便捷使用isEmpty()方法,isEmpty()判断list集合有没有元素,如果有元素返回false,没有返回true,如果集合本身设置为null,则会报...原创 2018-07-13 17:43:17 · 62921 阅读 · 9 评论 -
SimpleDateFormat时间格式转换12、24小时
Date d = new Date(); //获取当前时间 SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd hh:mm:ss");//转换时间格式为12小时制 System.out.println(sdf.format(d)); Simpl...转载 2018-08-07 16:24:14 · 3422 阅读 · 0 评论 -
list.clear()与list = null 区别
一 . list.clear()底层源码实现在使用list 结合的时候习惯了 list=null ;在创建这样的方式,但是发现使用list的clear 方法很不错,尤其是有大量循环的时候1、list 接口 的ArrayList 类的clear() 方法源码如下:/** * Removes all of the elements from this list. T...转载 2019-01-15 11:08:22 · 10637 阅读 · 0 评论 -
Mybatis 配置 返回自增长主键id
<insert id="insertXXX" useGeneratedKeys="true" keyProperty="id" parameterType="com.lan.vote.model.User"> //SQL语句</insert> useGeneratedKeys: 取值范围:true|false原创 2019-01-22 15:19:46 · 2942 阅读 · 0 评论