private transient Object[] elementData;
public ArrayList() {
this(10);
}
public ArrayList(int initialCapacity) {
super();
if (initialCapacity < 0)
throw new IllegalArgumentException("Illegal Capacity: "+
initialCapacity);
this.elementData = new Object[initialCapacity];
}
public ArrayList(Collection<? extends E> c) {
elementData = c.toArray();
size = elementData.length;
// c.toArray might (incorrectly) not return Object[] (see 6260652)
if (elementData.getClass() != Object[].class)
elementData = Arrays.copyOf(elementData, size, Object[].class);
}
public void add(int index, E element) {
rangeCheckForAdd(index);//验证(可以不考虑)
ensureCapacityInternal(size + 1); // Increments modCount!!(超过当前数组长度进行扩容)
System.arraycopy(elementData, index, elementData, index + 1,
size - index);(核心代码)
elementData[index] = element;
size++;
}
public static void main(String[] args){
/**
* 没有顺序可循,这是因为hashset采用的是散列(处于速度考虑)
*/
Random random=new Random(47);
Set<Integer> intset=new HashSet<Integer>();
for (int i=0;i<10000;i++){
intset.add(random.nextInt(30));
}
System.out.print(intset);
}
public static void main(String[] args){
Random random=new Random(47);
Set<Integer> intset=new TreeSet<Integer>();
for (int i=0;i<10000;i++){
intset.add(random.nextInt(30));
}
System.out.print(intset);
}
public static void main(String[] args){
Queue<Integer> queue=new LinkedList<Integer>();
Random rand=new Random();
for (int i=0;i<10;i++){
queue.offer(rand.nextInt(i+10));
}
printQ(queue);
Queue<Character> qc=new LinkedList<Character>();
for (char c:"HelloWorld".toCharArray()){
qc.offer(c);
}
System.out.println(qc.peek());
printQ(qc);
List<String> mystrings=new LinkedList<String>();
mystrings.add("1");
mystrings.get(0);
Set<String> a=new HashSet<String>();
Set<String> set=new HashSet<String>();
set.add("1");
}
public static void printQ(Queue queue){
while (queue.peek
public static void main(String[] args) {
PriorityQueue<Integer> priorityQueue = new PriorityQueue<Integer>();
Random rand = new Random();
for (int i = 0; i < 10; i++) {
priorityQueue.offer(rand.nextInt(i + 10));
}
QueueDemo.printQ(priorityQueue);
List<Integer>ints= Arrays.asList(25,22,20,18,14,9,3,1,1,2,3,9,14,18,21,23,25);
priorityQueue=new PriorityQueue<Integer>(ints);
QueueDemo.printQ(priorityQueue);
}
public static void main(String[] args){
//Map<String,String> pets=new HashMap<String, String>();
Map<String,String> pets=new TreeMap<String, String>();
pets.put("1","张三");
pets.put("2","李四");
pets.put("3","王五");
if (pets.containsKey("1")){
System.out.println("已存在键1");
}
if (pets.containsValue("张三")){
System.out.println("已存在值张三");
}
Set<String> sets=pets.keySet();
Set<Map.Entry<String , String>> entrySet= pets.entrySet();
Collection<String> values= pets.values();
for (String value:values){
System.out.println(value+";");
}
for (String key:sets){
System.out.print(key+";");
}
for (Map.Entry entry:entrySet){
System.out.println("键:"+entry.getKey());
System.out.println("值:"+entry.getValue());
}
}
public class IteratorClass {
public Iterator<String> iterator(){
return new Itr();
}
private class Itr implements Iterator<String>{
protected String[] words=("Hello Java").split(" ");
private int index=0;
public boolean hasNext() {
return index<words.length;
}
public String next() {
return words[index++];
}
public void remove() {
}
}
}
Iterator iterators=new IteratorClass().iterator();
for (Iterator it=iterator;iterators.hasNext();) {
System.out.println(iterators.next());
}
while (iterators.hasNext()){
System.out.println(iterators.next());
}
Iterator<String> iterator=userList.iterator();
while (iterator.hasNext()){
iterator.next();
iterator.remove();
}
机械节能产品生产企业官网模板...
大气智能家居家具装修装饰类企业通用网站模板...
礼品公司网站模板
宽屏简约大气婚纱摄影影楼模板...
蓝白WAP手机综合医院类整站源码(独立后台)...苏ICP备2024110244号-2 苏公网安备32050702011978号 增值电信业务经营许可证编号:苏B2-20251499 | Copyright 2018 - 2025 源码网商城 (www.ymwmall.com) 版权所有