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

最有效的网站推广方法网络营销广告策划

最有效的网站推广方法,网络营销广告策划,福田的网站建设公司哪家好,网站建设存在四个问题一、概述 有两种不同的方法来实现List接口。ArrayList类使用基于连续内存分配的实现,而LinkedList实现基于linked allocation。 list接口提供了一些方法: 二、The ArrayList and LinkedList Classes 1.构造方法 这两个类有相似的构造方法&#xff1a…

一、概述

有两种不同的方法来实现List接口。ArrayList类使用基于连续内存分配的实现,而LinkedList实现基于linked allocation

list接口提供了一些方法:

 二、The ArrayList and LinkedList Classes

1.构造方法

这两个类有相似的构造方法:

ArrayList()ArrayList(int initialCapacity)ArrayList(Collection<? extends E> c)
LinkedList()LinkedList(Collection<? extends E> c)

使用第三种构造方法可以将list转为arraylist:

import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;public class ArrayListDemo {public static void main(String[] args) {// 创建一个包含一些整数的列表List<Integer> numbers = Arrays.asList(1, 2, 3, 4, 5);// 使用 ArrayList(Collection<? extends E> c) 构造方法创建一个新的 ArrayList 对象ArrayList<Integer> arrayList = new ArrayList<>(numbers);// 打印 ArrayList 的内容System.out.println(arrayList);}
}

用for循环将数组转为linkedlist: 

// Initialize array of names.String [] namesArray = {"Anna", "Bob", "Carlos", "Debby"};// Create empty list.LinkedList<String> list1 = new LinkedList<>();// Populate the list using a loop.for (String s : namesArray){list1.add(s);}System.out.println(list1);

注意,java中的collection都自带toString方法,结果如下:

[Anna, Bob, Carlos, Debby]

 2.asList

我们可以不用for循环遍历,而直接把一个array转化为linkedlist或arraylist:

// Initialize array of names.
String[] namesArray = {"Anna", "Bob", "Carlos", "Debby"};// Create LinkedList from array using constructor.LinkedList<String> linkedList = new LinkedList<>(Arrays.asList(namesArray));

也可以这样:

LinkedList list2 =new LinkedList<>(Arrays.asList("Anna", "Bob", "Carlos", "Debby"));

3.linkedlist中的其他方法 

三、List Iterators

迭代器可以在列表中向前或向后移动。除了 next() 方法外,列表迭代器还有一个 previous() 方法,列表迭代器有一个光标位置,它总是位于调用 previous() 方法返回的元素和调用 next() 方法返回的元素之间。

最初,光标位于索引为 0 的元素之前。调用 next() 时,光标将返回索引为 0 的元素,并越过返回的元素向前移动到元素 0 和元素 1 之间的位置。此时,调用 previous() 将返回元素 0,并将光标移回起点,但调用 next() 将返回元素 1,并将光标向前移动到元素 1 和元素 2 之间的位置。如果光标已经越过最后一个元素,调用 next() 将抛出 NoSuchElementException 异常。同样,如果光标位置在元素 0 之前,调用 previous() 也会产生同样的异常。

列表迭代器中的 remove() 方法会从列表中删除最后一次调用 next() 或 previous() 时返回的元素

也就是说,如果在调用 `remove()` 方法之前没有先调用 `next()` 或 `previous()` 方法,那么会抛出一个 `IllegalStateException` 异常。

这是因为 `remove()` 方法的作用是删除迭代器最后访问的元素,所以在调用 `remove()` 方法之前必须先调用 `next()` 或 `previous()` 方法,以确保迭代器已经指向了要删除的元素。

如果在调用 `remove()` 方法之前没有先调用 `next()` 或 `previous()` 方法,那么迭代器没有指向任何元素,也就无法删除元素,因此会抛出 `IllegalStateException` 异常。

这里的迭代器的remove方法和list的remove方法不是一个东西,自然不能按原来的方式理解。

list的迭代器还提供了以下方法:

 例子:

import java.util.*;/*** Demonstrates the list iterator*/
public class ListIteratorDemo {public static void main(String[] args) {// Create an array list to hold strings.String[] names = {"Chris", "David", "Katherine", "Kenny"};List<String> nameList = new ArrayList<>(Arrays.asList(names));// Display the names in the list.System.out.println("Here are the original names.");System.out.println(nameList);// Get a list iterator.ListIterator<String> it = nameList.listIterator();// Add "Darlene" to the list right after "Chris".while (it.hasNext()) {String str = it.next();// If the last name retrieved was "Chris"// then insert "Darlene".if (str.equalsIgnoreCase("Chris")) {it.add("Darlene");// We are donebreak;}}//Display the names in the list again.System.out.println("\nHere are the new names now.");System.out.println(nameList);}
}

Here are the original names.

[Chris, David, Katherine, Kenny]

Here are the new names now.

[Chris, Darlene, David, Katherine, Kenny]

 四、用list接口变量去引用linkedlist或arraylist

推荐使用

List<String> nameList = new ArrayList<>();

而不是

 ArrayList<String> nameList = new ArrayList<>();

因为第一种方法后期容易修改。

比如在后期发现namelist实际上应该使用linkedlist,这是只需要把第一句改成:

List<String> myList = new LinkedList<>();

这时,项目中所有的myList就都变成了Linkedlist。

如果用第二种方法,我们在项目中别的地方传参的时候,会传入(arraylist nameList),这时如果要换成Linkedlist,我们需要改变所有传入参数的类型。

使用第一种方法,我们传的参数是(List nameList),就不需改变。

http://www.tj-hxxt.cn/news/77573.html

相关文章:

  • 网站系统 外贸重庆整站seo
  • 网站设计制作怎样可以快速营销宝
  • ps个人网站建设湖南seo网站策划
  • wordpress移动端音频播放aso优化
  • wordpress park主题seo搜索排名优化方法
  • 重庆建站公司网站模板深圳seo教程
  • 如何做一名合格的网站人武汉seo网站排名优化
  • 在电脑上怎么做网站跨境电商seo是什么意思
  • 什么网站做玩具的外贸广州百度推广开户
  • ps做网站界面黄桃图片友情链接
  • 做素描的网站教育机构加盟
  • 建筑网站带图解北京网站优化托管
  • 车辆管理网站开发产品推广策划书
  • 专做写字楼出租的网站百度服务中心投诉
  • 交通银行网站开发沈阳专业seo
  • 在线做数据图的网站有哪些问题搜索关键词优化排名
  • 有人做几个蝎子养殖门户网站网络营销公司做什么
  • 企业管理课程有哪些内容扬州seo推广
  • 最新人才招聘网seo编辑培训
  • 做html网站模板广告有限公司
  • 制作网站作业seo如何优化网站步骤
  • 网站开发学什么语言好seo和sem
  • 金华开发区人才网崇左seo
  • 后台给网站做关键字福州seo
  • 手机销售网站建设项目书佛山seo培训
  • 旅游网站建设方案书企业网搭建
  • 如何购买虚拟主机做网站下载优化大师
  • dwcc怎么做网站制作网站的基本步骤
  • 自学建设网站比较靠谱的电商培训机构
  • 网站更新提示ui怎末做业务推广网站