随笔分类 - java
摘要:* && 短路与判断 ``` public class ImoocStudent { public static void main(String[] args) throws Exception{ if(1 > 2 && 10/0 == 0)// 执行报错,0不能作为分母 { System.out
阅读全文
摘要:``` public static void main(String[] args) throws Exception{ char c = '建'; System.out.println((int)c); boolean flag = 24314 == c;// -- 不同的字符类型,这里有个自动转
阅读全文
摘要:### 在Java中,字符型和字符串类型都是常用的数据类型,但是它们有着本质的不同。 * 字符型是基本数据类型,表示单个字符,使用char表示。例如:'A'、'1'、'中'等。 * 字符串类型是引用数据类型,表示由多个字符组成的字符串,使用String表示。例如:"hello"、"world"、"你
阅读全文
摘要:* 以下实例演示了如何使用 Collections 类的 replaceAll() 来替换List中所有的指定元素: ``` import java.util.Arrays; import java.util.Collections; import java.util.List; public cl
阅读全文
摘要:* 它的作用是将列表中的元素向右移动指定的距离,如果移动的距离是负数,则表示向左移动。 方法的声明如下: public static void rotate(List list,int distance) 其中,list 是要进行移动的List集合,distance 是指移动的距离,可以是正数或负数
阅读全文
摘要:TreeMap是Java中的一个类,它实现了Map接口,利用红黑树数据结构来有序存储键值对。 TreeMap中的键按升序排序,若要自定义排序方式,则可以提供自定义的比较器。 TreeMap实现了高效的数据访问、插入和删除操作,大多数常规操作的时间复杂度为O(log n)。 ``` import ja
阅读全文
摘要:Java1.5提供了一个叫varargs的新功能,就是可变长度的参数。 "Varargs"是"variable number of arguments"的意思。有时候也被简单的称为"variable arguments" 定义实参个数可变的方法:只要在一个形参的"类型"与"参数名"之间加上三个连续的
阅读全文
摘要:## demo1 ``` import java.util.ArrayList; import java.util.Iterator; import java.util.List; public class ImoocStudent { public static void main(String[
阅读全文
摘要:* Java 中的标签是为循环设计的,是为了在多重循环中方便的使用 break 和coutinue ### demo1 ``` public static void main(String[] args) throws Exception{ label:// 放在这里label,跳出外出循环 for
阅读全文
摘要:``` import java.text.SimpleDateFormat; import java.util.Date; public class ImoocStudent { public static void main(String[] args) throws Exception{ for
阅读全文
摘要:### System.out.printf() * %d 指定输出整型 * %s 指定字符串类型 * %.2f 浮点数字的格式 { ArrayList objArray = new ArrayL
阅读全文
摘要:* 在 Java 中,我们可以使用 ArrayList 来定义不固定长度的数组,因为 ArrayList 内部使用了一个动态数组来存储元素。 * arrayList 是动态数组 * 添加数组 ``` ArrayList intList = new ArrayList(); intList.add(1
阅读全文
摘要:``` import java.util.*; public class ImoocStudent { public static void main(String args[]){ int array[] = new int[6]; Arrays.fill(array,100); for (int
阅读全文
摘要:* 以下实例演示了如何通过 Collections 类的 Collections.max() 和 Collections.min() 方法来查找数组中的最大和最小值: ``` import java.util.Arrays; import java.util.Collections; public
阅读全文
摘要:
阅读全文
摘要:
阅读全文
摘要:``` public static void main(String args[]){ int[] source = {1,2,3,4,5,6,7}; int[] target = new int[5]; System.arraycopy(source,0,target,0,5);// 6,7超出5
阅读全文
摘要:
阅读全文
摘要:``` import java.util.ArrayList; import java.util.Vector; import java.util.Arrays; public class ImoocStudent { public static void main(String args[]){
阅读全文