当前位置: 首页 > news >正文

互联网加项目策划书小吴seo博客

互联网加项目策划书,小吴seo博客,微信 网站建设,如何用ad做网站❤️ Author: 老九 ☕️ 个人博客:老九的CSDN博客 🙏 个人名言:不可控之事 乐观面对 😍 系列专栏: 文章目录 collectionCollection创建collection使用泛型collection方法 Map 接口Map的存储结构HashMap和Tr…

❤️ Author: 老九
☕️ 个人博客:老九的CSDN博客
🙏 个人名言:不可控之事 乐观面对
😍 系列专栏:

文章目录

  • collection
    • Collection创建
    • collection使用泛型
    • collection方法
  • Map 接口
    • Map的存储结构
    • HashMap和TreeMap的有序和无序
  • 包装类
    • 装箱与拆箱(装包与拆包)
  • LIst
    • List使用
    • List的多种输出方式
      • 直接通过字符串输出
      • 通过for循环打印
      • 通过foreach输出
      • 通过迭代器打印
    • List的API
      • add
      • 通过增加一个参数index的add方法
      • 把一个 List 放在另一个 List 后面
      • 删除某个值
      • 获取某个下标的值
      • 更改某个位置的值
      • 清空List
  • Map的API
    • put
    • get
    • getOrDefault
    • remove
  • Set的API
    • set 自动去重
    • contains是否包含
    • remove删除
    • isEmpty()判空
    • clear()清空
  • 静态内部类

collection

在这里插入图片描述

Collection 接口,在 Java 当中,Collection 也是重要的数据结构。

Collection创建

在创建 Collection 的时候,要通过 new 关键字来使用。但是查看 Collection 源码的时候,发现 Collecting 是一个接口
在这里插入图片描述
**因为接口是不能实例化的,所以 new 的时候,要用一个具体的类。**这里用ArrayList来举例:

Collection collection = new ArrayList();

collection使用泛型

使用泛型就是加上 <> 里面写元素类型,要注意的是,这里的类型全是包装类。字符串的包装类是:String 整形的包装类是:Integer 。写了包装类的话,add 的时候就只能添加这一类型:

public static void main(String[] args) {Collection<String> collection = new ArrayList<String>();collection.add("hello");collection.add("word");System.out.println(collection);
}

Collection 后面的 String 可以不写,因为不写的话,编译器会通过前面的 String 来推导出相应的类型。如果这里 add 非字符类型的话,就会报错。运行结果如下:
在这里插入图片描述

collection方法

Collection 里面有很多自带的方法:
在这里插入图片描述
使用代码测试:

public static void main(String[] args) {Collection<String> collection = new ArrayList<>();collection.add("hello");collection.add("word");System.out.println(collection);System.out.println(collection.size());System.out.println(collection.isEmpty());collection.remove("word");System.out.println(collection);Object[] objects = collection.toArray();System.out.println(Arrays.toString(objects));System.out.println(objects);
}

在这里插入图片描述

Map 接口

Map 是在 util 包下的接口。Map 有两个参数 <key,val> ,而且这两个参数必须是字符串。实现 Map 的方法 有HashMap 和 TreeMap 。Map 的基本功能如下
在这里插入图片描述

public static void main(String[] args) {Map<String,String> map = new HashMap<>();map.put("Lockey","鲁班锁");map.put("及时雨","宋江");String ret = map.get("及时雨");String tmp = map.getOrDefault("及时雨1","FM850");System.out.println(ret);System.out.println(tmp);boolean flag = map.containsKey("Lockey");System.out.println(flag);
}

在这里插入图片描述

Map的存储结构

  • map在存储的时候,并不是顺序存储的,而是通过映射去存储的。代码示例:
public static void main(String[] args) {Map<String,String> map = new HashMap<>();map.put("及时雨","宋江");map.put("Lockey","鲁班锁");System.out.println(map);
}

先输出 “Lockey” 然后才是 “及时雨” 。
在这里插入图片描述

HashMap和TreeMap的有序和无序

  • HashMap存储的时候是根据key值排序的,是有序的。
  • TreeMap放入的时候没有进行比较,没有排序。
public static void main(String[] args) {Map<Integer,String> map = new HashMap<>();map.put(10,"宋江");map.put(3,"鲁班锁");System.out.println(map);Map<String,String> map2 = new HashMap<>();map2.put("efg","宋江");map2.put("abc","鲁班锁");System.out.println(map2);Map<String,String> map3 = new TreeMap<>();map3.put("及时雨","宋江");map3.put("国民女神","鲁班锁");System.out.println(map3);Map<String,String> map4 = new HashMap<>();map4.put("及时雨","宋江");map4.put("国民女神","鲁班锁");System.out.println(map4);
}

在这里插入图片描述

包装类

包装类是根据基本类型出现的,八大基本类型对应着八种包装类:
在这里插入图片描述
要注意的是:String 不是包装类。**包装类的好处在于:可以完成对数据的操作。**例如:把字符串变为整形:

public static void main(String[] args) {String str = "123";int ret = Integer.valueOf(str);System.out.println(ret+1);
}

在这里插入图片描述

装箱与拆箱(装包与拆包)

装箱:把简单数据类型变为包装类类型
拆箱:把包装类类型变为简单数据类型

代码示例,这里是隐式的:

public static void main(String[] args) {//装箱Integer a = 123;//拆箱int b = a;//隐式的:因为把 Integer 变为 int 了System.out.println(a+"   "+b);
}

在这里插入图片描述
下面我们通过 powershell 窗口来看编译的过程:
在这里插入图片描述
可以看到,画圈的部分就是两次过程。第一次是通过 Integer 的 valueOf 来把 123 变成 Integer 类。第二次则是通过 Integer 的 intValue 来变成 int 类型。下面的就是字符串的拼接了。
显式拆包:
通过直接将方法写出来,一看就明白了的方法就是显式的:

public static void main(String[] args) {//这里就是显式的装包Integer a2 = Integer.valueOf(123);Integer a3 = new Integer(123);//显式的拆包int b2 = a2.intValue();double d = a2.doubleValue();
}

LIst

List使用

在使用 List 的时候,后面括号可以加参数,也可以不加参数,加的参数是表示容量大小:

public static void main(String[] args) {List<String> list1 = new ArrayList<>(20);List<String> list2 = new ArrayList<>();
}

List 是一个很大的类,这里用它下层的 ArrayList :

public static void main(String[] args) {ArrayList<String> list2 = new ArrayList<>();list2.add("hello");list2.add("word");list2.add("123");System.out.println(list2);ArrayList<String> list3 = new ArrayList<>(list2);System.out.println(list3);
}

在这里插入图片描述
可以使用另外一个 Array List 对 list 初始化:这里的 list3 就是用 list2 来进行初始化。

List的多种输出方式

直接通过字符串输出

public static void main(String[] args) {ArrayList<String> list2 = new ArrayList<>();list2.add("hello");list2.add("word");list2.add("123");System.out.println(list2);
}

在这里插入图片描述

通过for循环打印

- 用size()获取长度,用add()添加,用get(int)获取

public static void main(String[] args) {ArrayList<String> list2 = new ArrayList<>();list2.add("hello");list2.add("word");list2.add("123");for (int i = 0; i < list2.size(); i++){System.out.println(list2.get(i));}
}

在这里插入图片描述

通过foreach输出

public static void main(String[] args) {ArrayList<String> list2 = new ArrayList<>();list2.add("hello");list2.add("word");list2.add("123");for (String s:list2) {System.out.println(s);}
}

在这里插入图片描述

通过迭代器打印

  • 通过使用List的方法:iterator()来完成输出
public static void main(String[] args) {ArrayList<String> list2 = new ArrayList<>();list2.add("hello");list2.add("word");list2.add("123");System.out.println("迭代器打印");Iterator<String> i = list2.iterator();while (i.hasNext()) {System.out.println(i.next());}
}

在这里插入图片描述

List的API

add

List 当中的 add 方法,默认是放在最后一个位置的:

public static void main(String[] args) {//add 方法 默认是放到数组的最后一个位置的ArrayList<String> list = new ArrayList<>();list.add("a");list.add("b");list.add("c");System.out.println(list);
}

在这里插入图片描述

通过增加一个参数index的add方法

通过在 add 方法放第一次参数,将元素放到某个位置下面:

public static void main(String[] args) {ArrayList<String> list = new ArrayList<>();list.add("a");list.add("b");list.add("c");System.out.println(list);list.add(0,"Lockey");System.out.println(list);
}

在这里插入图片描述

把一个 List 放在另一个 List 后面

通过 List 的方法 addALL 来完成,代码如下:

public static void main(String[] args) {ArrayList<String> list = new ArrayList<>();list.add("a");list.add("b");list.add("c");System.out.println(list);ArrayList<String> list1 = new ArrayList<>();list1.add("qwe");list1.add("rty");list1.addAll(list);System.out.println(list1);
}

在这里插入图片描述

删除某个值

通过 remove 方法来完成删除:

public static void main9(String[] args) {ArrayList<String> list = new ArrayList<>();list.add("a");list.add("b");list.add("c");System.out.println(list);boolean flag = list.remove("a");System.out.println(flag);System.out.println(list);
}

在这里插入图片描述

获取某个下标的值

通过 get 方法来完成获取:

public static void main(String[] args) {ArrayList<String> list = new ArrayList<>();list.add("a");list.add("b");list.add("c");String ret = list.get(1);System.out.println(ret);
}

在这里插入图片描述

更改某个位置的值

通过 set 方法来完成:

public static void main(String[] args) {ArrayList<String> list = new ArrayList<>();list.add("a");list.add("b");list.add("c");list.set(1,"d");System.out.println(list);
}

在这里插入图片描述

清空List

通过 clear 方法来完成:

public static void main(String[] args) {ArrayList<String> list = new ArrayList<>();list.add("a");list.add("b");list.add("c");list.clear();System.out.println(list);
}

在这里插入图片描述

Map的API

map 和 set 是一种专门用来搜索和查询的容器或数据结构,效率很高。是为了解决在 “增删查改” 情况下使用的数据结构。
HashMap 在存储元素的时候,是根据一个函数进行存储的,具体存储到哪里,由函数来确定。这个函数就是哈希函数。所以输出的时候,并不是按照存储顺序进行输出的。Map是一个接口类,没有继承自Collection,类中存储的是 <K,V> 结构的键值对,并且 K 一定是唯一的,不能重复。在遇到相同的 K 的时候,V 是可以改变的。

put

在 map 当中,put 是放入元素的意思,有两个参数,第一个是 key ,第二个是 value ,代码如下:

public static void main(String[] args) {Map<String, Integer> map = new HashMap<>();map.put("abc",3);map.put("word",2);map.put("hello",4);System.out.println(map);
}

在这里插入图片描述
输出的时候按照key值从大到小输出。
put 如果存储元素的时候,如果 key 值相同的话,val 值会覆盖。代码如下:

public static void main(String[] args) {Map<String, Integer> map = new HashMap<>();map.put("abc",3);map.put("word",2);map.put("hello",4);map.put("abc",5);System.out.println(map);
}

在这里插入图片描述

get

使用 get 通过 key 来获取对应的 value 的值。代码如下:

public static void main(String[] args) {Map<String, Integer> map = new HashMap<>();map.put("abc",3);map.put("word",2);map.put("hello",4);int ret = map.get("abc");System.out.println(ret);
}

在这里插入图片描述

getOrDefault

getOrDefault 方法有两个参数,一个是 key ,如果没有 key 的话,就返回设置的默认值。如果有 key 的话,就返回 key 的 value 。代码如下:

public static void main(String[] args) {Map<String, Integer> map = new HashMap<>();map.put("abc",3);map.put("word",2);map.put("hello",4);System.out.println(map.getOrDefault("abc",98));
}

因为 abc 存在,所以返回 abc 的 value 。就是 3 。
在这里插入图片描述

remove

remove 方法有一个参数,参数是输入的 key ,返回对应的 value 。如果没有 key 的话,就返回 null 。代码如下:

public static void main(String[] args) {Map<String, Integer> map = new HashMap<>();map.put("abc",3);map.put("word",2);map.put("hello",4);Integer ret2 = map.remove("abc");System.out.println(ret2);
}

在这里插入图片描述

Set的API

set 是一个集合,存入里面的数据会自动去重。Set 是继承自 Collection 的接口类,Set 中只存储了 Key 。

set 自动去重

放入 set 的数据会自动去重,代码如下:

public static void main4(String[] args) {Set<Integer> set = new HashSet<>();set.add(1);set.add(2);set.add(3);set.add(1);System.out.println(set);
}

在这里插入图片描述

contains是否包含

remove删除

isEmpty()判空

clear()清空

静态内部类

1.外部类可通过内部类的对象调用内部类的私有成员变量或方法。
2.静态内部类访问外部类的静态成员变量或方法必须是静态的。


♥♥♥码字不易,大家的支持就是我坚持下去的动力♥♥♥
版权声明:本文为CSDN博主「亚太地区百大最帅面孔第101名」的原创文章


文章转载自:
http://autarch.qkqn.cn
http://chyle.qkqn.cn
http://orthopteron.qkqn.cn
http://trike.qkqn.cn
http://lepus.qkqn.cn
http://exegetically.qkqn.cn
http://epode.qkqn.cn
http://cupola.qkqn.cn
http://pianette.qkqn.cn
http://adactylous.qkqn.cn
http://pinchers.qkqn.cn
http://nape.qkqn.cn
http://lahar.qkqn.cn
http://unequaled.qkqn.cn
http://incinerate.qkqn.cn
http://inaptly.qkqn.cn
http://hiroshima.qkqn.cn
http://relative.qkqn.cn
http://bushed.qkqn.cn
http://coercivity.qkqn.cn
http://lineament.qkqn.cn
http://sukkur.qkqn.cn
http://limply.qkqn.cn
http://misbelief.qkqn.cn
http://ashes.qkqn.cn
http://arytenoidal.qkqn.cn
http://blowout.qkqn.cn
http://condensery.qkqn.cn
http://discoverture.qkqn.cn
http://freaky.qkqn.cn
http://perianth.qkqn.cn
http://etta.qkqn.cn
http://heaver.qkqn.cn
http://killed.qkqn.cn
http://gama.qkqn.cn
http://refrigeratory.qkqn.cn
http://virtual.qkqn.cn
http://antheap.qkqn.cn
http://gridding.qkqn.cn
http://peccary.qkqn.cn
http://inapparent.qkqn.cn
http://baronetage.qkqn.cn
http://naeb.qkqn.cn
http://oersted.qkqn.cn
http://highly.qkqn.cn
http://agrarian.qkqn.cn
http://gulp.qkqn.cn
http://retinite.qkqn.cn
http://diabetogenic.qkqn.cn
http://anjou.qkqn.cn
http://martellato.qkqn.cn
http://perspicuously.qkqn.cn
http://apace.qkqn.cn
http://figuration.qkqn.cn
http://hydremic.qkqn.cn
http://inkberry.qkqn.cn
http://frostbite.qkqn.cn
http://confederative.qkqn.cn
http://presentable.qkqn.cn
http://emily.qkqn.cn
http://wetware.qkqn.cn
http://escarp.qkqn.cn
http://tweeny.qkqn.cn
http://microcalorie.qkqn.cn
http://superabundance.qkqn.cn
http://thermopane.qkqn.cn
http://bravest.qkqn.cn
http://undergraduate.qkqn.cn
http://droll.qkqn.cn
http://ocellation.qkqn.cn
http://sociopath.qkqn.cn
http://luff.qkqn.cn
http://intermediation.qkqn.cn
http://sap.qkqn.cn
http://gingerade.qkqn.cn
http://antiscorbutic.qkqn.cn
http://psittacosis.qkqn.cn
http://unshirkable.qkqn.cn
http://military.qkqn.cn
http://cosmogeny.qkqn.cn
http://mitten.qkqn.cn
http://pajamas.qkqn.cn
http://clamjamfry.qkqn.cn
http://xanthochroi.qkqn.cn
http://unsaddle.qkqn.cn
http://isogenic.qkqn.cn
http://ameloblast.qkqn.cn
http://hypertrophy.qkqn.cn
http://aeromagnetic.qkqn.cn
http://wynd.qkqn.cn
http://staccato.qkqn.cn
http://apparatus.qkqn.cn
http://dm.qkqn.cn
http://polyspermous.qkqn.cn
http://scientism.qkqn.cn
http://alias.qkqn.cn
http://rural.qkqn.cn
http://toolmaking.qkqn.cn
http://keywords.qkqn.cn
http://coordination.qkqn.cn
http://www.dt0577.cn/news/23052.html

相关文章:

  • 网站的引导页怎么做的谷歌排名查询
  • 如何验证网站学新媒体运营最好的培训学校
  • 电子版证件照免费制作微信小程序seo外链查询工具
  • 开网站需要哪些程序华为seo诊断及优化分析
  • 如何做一名网站编辑沈阳seo网站关键词优化
  • 网站系统下载广州seo全网营销
  • 架设时时彩网站需要怎么做杭州优化seo
  • 国外网站流量中国免费网站服务器主机域名
  • php中做购物网站的教程百度搜索风云榜官网
  • 交互效果好的网站网站优化公司
  • 域名和主机有了怎么做网站灯塔网站seo
  • 自己做的网站怎么弄成appsem搜索
  • ps怎么做网站首页界面大数据营销案例
  • 怎么将网站做成html2024近期新闻
  • 网页设计欣赏熊出没关键词优化排名软件流量词
  • 可以做秋招笔试题的网站googlechrome
  • 北京网站建设公司服务有哪些陕西新闻今日头条
  • 珲春住房和城乡建设局网站软文范文200字
  • 包头做网站企业网上培训课程平台
  • 如何网站做外贸生意搜索引擎排名
  • wordpress主题和插件西安网络推广优化培训
  • web程序设计asp.net实用网站开发课后上机操作题答案品牌网站建设公司
  • 在深圳注册公司需要多少钱海淀区seo搜索优化
  • 新疆锦旭建设工程公司网站有趣的软文
  • 山东大型网站建设营销策划与运营方案
  • 技术先进的网站建设推广软件的app
  • 响应式网站模板htmlseo搜索引擎优化案例
  • 如何将aaa云主机做网站网站关键词优化公司
  • 怎么做兼职类网站吗怎么做互联网营销推广
  • 福州网站建站公司济南今日头条最新消息