Java.util.ArrayList
======================================================================
import java.util.ArrayList;
public class arrayList {
public static void main(String args[])
{
ArrayList<String> mylist= new ArrayList<String>();
mylist.add("sree");
mylist.add("krishna");
for(String str:mylist)
System.out.println(str);
}
}
======================================================================
import java.util.ArrayList;
class arrayList{
public static void main(String args[])
{
ArrayList<Integer> mylist= new ArrayList<Integer>();
mylist.add(9);
mylist.add(6);
mylist.add(1);
for(int x:mylist)
System.out.println(x);
}
}
======================================================================
import java.util.ArrayList;
class arrayList{
public static void main(String args[])
{
ArrayList<Integer> mylist = new ArrayList<Integer>(5);
mylist.add(1);
mylist.add(2);
mylist.add(4);
mylist.add(5);
for(int x:mylist)
System.out.println(x);
System.out.println("===========");
mylist.add(2,3); //index starts from zer0
for(int x: mylist)
System.out.println(x);
}
}
======================================================================
import java.util.ArrayList;
class arrayList{
public static void main(String args[])
{
ArrayList<Integer> list1= new ArrayList<Integer>(5);
list1.add(1);
list1.add(2);
list1.add(3);
for(Integer x: list1)
System.out.println(x);
System.out.println("===============");
ArrayList<Integer> list2 =new ArrayList<Integer>(5);
list2.add(4);
list2.add(5);
list2.add(6);
for(Integer y:list2)
System.out.println(y);
System.out.println("===============");
list1.addAll(list2);
for(Integer x: list1)
System.out.println(x);
System.out.println("===============");
for(Integer y:list2)
System.out.println(y);
System.out.println("===============");
}
}
======================================================================
import java.util.ArrayList;
class arrayList{
public static void main(String args[])
{
ArrayList<Integer> list1= new ArrayList<Integer>(5);
list1.add(1);
list1.add(5);
list1.add(6);
for(Integer x: list1)
System.out.println(x);
System.out.println("===============");
ArrayList<Integer> list2 =new ArrayList<Integer>(5);
list2.add(2);
list2.add(3);
list2.add(4);
for(Integer y:list2)
System.out.println(y);
System.out.println("===============");
list1.addAll(1,list2);
for(Integer y:list1)
System.out.println(y);
System.out.println("===============");
}
}
======================================================================
import java.util.ArrayList;
public class arrayList{
public static void main(String args[])
{
ArrayList<Integer> mylist = new ArrayList<Integer>();
mylist.add(2);
mylist.add(5);
mylist.add(6);
System.out.println("size of the list: "+mylist.size());
mylist.clear();
System.out.println("size of the list: "+mylist.size());
}
}
======================================================================
import java.util.ArrayList;
public class arrayList{
public static void main(String args[])
{
ArrayList<Integer> mylist =new ArrayList<Integer>(5);
mylist.add(5);
mylist.add(9);
mylist.add(21);
boolean isThere;
isThere=mylist.contains(9);
System.out.println(isThere);
}
}
======================================================================
import java.util.ArrayList;
public class arrayList{
public static void main(String args[])
{
ArrayList<Integer> mylist =new ArrayList<Integer>(5);
mylist.add(5);
mylist.add(9);
mylist.add(21);
mylist.add(34);
boolean isThere;
isThere=mylist.contains(9);
System.out.println(isThere);
System.out.println(mylist.size());
int res=mylist.get(2);
System.out.println("res: "+res);
}
}
======================================================================
import java.util.ArrayList;
public class arrayList{
public static void main(String args[])
{
ArrayList<String> mylist = new ArrayList<String>(5);
mylist.add("a");
mylist.add("b");
mylist.add("c");
mylist.add("d");
int res= mylist.indexOf("b");
System.out.println(res);
}
}
======================================================================
import java.util.ArrayList;
public class arrayList{
public static void main(String args[])
{
ArrayList<String> mylist = new ArrayList<String>(5);
mylist.add("a");
mylist.add("b");
mylist.add("c");
mylist.add("d");
mylist.add("c");
mylist.add("b");
mylist.add("c");
mylist.add("d");
int res= mylist.indexOf("b");
System.out.println(res);
boolean isEmpty;
isEmpty = mylist.isEmpty();
System.out.println(isEmpty);
for(String x:mylist)
System.out.println(x);
int lastIndex;
lastIndex=mylist.lastIndexOf("c");
System.out.println(lastIndex);
}
}
======================================================================
import java.util.ArrayList;
public class arrayList
{
public static void main(String args[])
{
ArrayList<Integer> mylist =new ArrayList<Integer>(5);
mylist.add(5);
mylist.add(9);
mylist.add(4);
System.out.println("size of the list: "+mylist.size());
for(Integer x: mylist)
{ System.out.print(x);System.out.print(",");
}
mylist.remove(1);
System.out.println("size of the list: "+mylist.size());
for(Integer x: mylist)
{ System.out.print(x);System.out.print(",");
}
}
}
======================================================================
java.util.HashMap
import java.util.HashMap;
public class hashMap {
public static void main(String args[])
{
HashMap mymap = new HashMap();
mymap.put(1, "apple");
mymap.put(2, "samsung");
mymap.put(3,"nokia");
System.out.println(mymap);
mymap.clear();
System.out.println(mymap);
}
}
======================================================================
import java.util.HashMap;
public class hashMap
{
public static void main(String args[])
{
HashMap mymap = new HashMap();
HashMap secnd = new HashMap();
mymap.put(1, "english");
mymap.put(2, "hindi");
mymap.put(3, "telugu");
System.out.println(mymap);
secnd=(HashMap)mymap.clone();
System.out.println(secnd);
}
}
======================================================================
import java.util.HashMap;
public class hashMap
{
public static void main(String args[])
{
HashMap mymap = new HashMap();
mymap.put(1, "english");
mymap.put(2, "hindi");
mymap.put(3, "telugu");
mymap.put(5, "");
System.out.println(mymap.containsKey(2)); //checks if key present
System.out.println(mymap.containsValue("hindi")); // checks if value present
}
}
======================================================================
import java.util.HashMap;
import java.util.Set;
public class hashMap{
public static void main(String args[])
{
HashMap test =new HashMap();
test.put(1, "C");
test.put(2, "c++");
test.put(3,"Java");
Set myset=test.entrySet();
System.out.println(myset); //entry set
System.out.println(test); // printing normal map
}
}
======================================================================
======================================================================
======================================================================
======================================================================
======================================================================