Java Collection

转载 2015年11月17日 22:50:06

Java ArrayList class

Java ArrayList class uses a dynamic array for storing the elements.
It extends AbstractList class and implements List interface.
Java ArrayList class can contain duplicate elements.
Java ArrayList class maintains insertion order.
Java ArrayList class is non synchronized.
Java ArrayList allows random access because array works at the index basis.
In Java ArrayList class, manipulation is slow because a lot of shifting needs to be occurred if any element is removed from the array list.

ArrayList al=new ArrayList();//creating old non-generic arraylist  
ArrayList<String> al=new ArrayList<String>();
//creating new generic arraylist  
import java.util.*;  
class TestCollection1{  
 public static void main(String args[]){  

  ArrayList<String> al=new ArrayList<String>();//creating arraylist  
  al.add("Ravi");//adding object in arraylist  
  al.add("Vijay");  
  al.add("Ravi");  
  al.add("Ajay");  

  Iterator itr=al.iterator();
  //getting Iterator from arraylist to traverse elements  
  while(itr.hasNext()){  
   System.out.println(itr.next());  
  }  
 }  
} 
import java.util.*;  
class TestCollection2{  
 public static void main(String args[]){  
  ArrayList<String> al=new ArrayList<String>();  
  al.add("Ravi");  
  al.add("Vijay");  
  al.add("Ravi");  
  al.add("Ajay");  
  for(String obj:al)  
    System.out.println(obj);  
 }  
}  

User-defined class objects in Java ArrayList

class Student{  
  int rollno;  
  String name;  
  int age;  
  Student(int rollno,String name,int age){  
   this.rollno=rollno;  
   this.name=name;  
   this.age=age;  
  }  
} 
import java.util.*;  
public class TestCollection3{  
 public static void main(String args[]){  
  //Creating user-defined class objects  
  Student s1=new Student(101,"Sonoo",23);  
  Student s2=new Student(102,"Ravi",21);  
  Student s2=new Student(103,"Hanumat",25);  

  ArrayList<Student> al=new ArrayList<Student>();//creating arraylist  
  al.add(s1);//adding Student class object  
  al.add(s2);  
  al.add(s3);  

  Iterator itr=al.iterator();  
  //traversing elements of ArrayList object  
  while(itr.hasNext()){  
    Student st=(Student)itr.next();  
    System.out.println(st.rollno+" "+st.name+" "+st.age);  
  }  
 }  
}  

compareto and comparable when do you use?
reverse,
collection and map
unique key, we cannot have duplicate key
sort, code compareto and comparable
tree traverse collections

相关文章推荐

java基础学习--Collection集合

------Java培训、Android培训、iOS培训、.Net培训、期待与您交流! ------- 1、集合类概述    1)面向对象对事物的体现都是以对象的形式,那么为了方便对多个对象的操作...

java Collection类整理

  • 2015-07-08 22:46
  • 42KB
  • 下载

Java集合类(Collection)学习

  • 2014-06-10 10:33
  • 28KB
  • 下载

Collection 集合框架 体系概述 java

java是面向对象的语言,用数组存储数据,用集合类存储对象。数组也可存储对象,但数组长度固定,而集合长度可变。数组可存储同种基本数据类型(定义时指明数据类型),集合可存储不同数据类型的对象。而容器对数...

java Collection&amp;Map

  • 2008-05-11 10:00
  • 158KB
  • 下载

黑马程序员--------java Collection、Map集合 、泛型

-----------android培训、java培训、java学习型技术博客、期待与您交流!------------ 一、Collection 集合 1、Collection集合结构...

JAVA COLLECTION PDF

  • 2014-10-15 15:53
  • 1.86MB
  • 下载
内容举报
返回顶部
收藏助手
不良信息举报
您举报文章:深度学习:神经网络中的前向传播和反向传播算法推导
举报原因:
原因补充:

(最多只允许输入30个字)