Write a program that prints out the lists alter the followin
Solution
Below is the program that implements all requirements. Program is tested fully and its working fine.To test each method just copy paste all program in your IDE/Compiler and remove comment character before method call.
If you have any doubt please so comments.
import java.util.*;
import java.io.*;
class HelloWorld
{
public static void main(String args[]) throws IOException
{
// System.out.println(myMethod());
ArrayList al=new ArrayList();
al.add(1);
al.add(3);
al.add(9);
al.add(7);
al.add(8);
al.add(4);
ArrayList tl=new ArrayList();
tl.add(1);
tl.add(2);
tl.add(6);
tl.add(9);
tl.add(10);
tl.add(15);
Integer min = (Integer)3;
Integer max = (Integer)5;
//minToFront(al);
//filterRange(al,min,max);
//intersect(al,tl);
}
public static void minToFront(ArrayList al)
{
Integer temp = (Integer)al.get(0);
int count = 0;
// System.out.println(temp);
for(int i=1;i<al.size();i++)
{
if((Integer)al.get(i) < temp)
{
temp =(Integer) al.get(i);
count = i;
}
}
al.remove(count);
al.add(0,temp);
Iterator itr=al.iterator();
while(itr.hasNext()){
System.out.println(itr.next());
}
}
public static void filterRange(ArrayList al,Integer min, Integer max)
{
for(int i=0;i<al.size();i++)
{
if((Integer)al.get(i) <= max && (Integer)al.get(i) >= min)
{
al.remove(i);
}
}
Iterator itr=al.iterator();
while(itr.hasNext()){
System.out.println(itr.next());
}
}
public static void intersect(ArrayList al,ArrayList tl)
{
ArrayList temp=new ArrayList();
for(int i=0;i<al.size();i++)
{
if(tl.contains(al.get(i)))
{
temp.add(al.get(i));
}
}
Iterator itr=temp.iterator();
while(itr.hasNext()){
System.out.println(itr.next());
}
}
}

