bhushan23

linkedlist&thread

Jul 14th, 2012
118
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.21 KB | None | 0 0
  1. import java.util.*;
  2.  
  3. class thread1 implements Runnable
  4. {
  5.     Thread t;
  6.     thread1(String n){
  7.  t=new Thread(this,n);
  8. t.start();
  9.     }
  10. public void run()
  11.     {
  12.         LinkedList name= new LinkedList();
  13.         name.add("sonawane");
  14.         name.addFirst("bhushan");
  15.         name.add(1, "bhalchandra");
  16. System.out.println("content of name "+name);
  17.          name.set(0," BhUsHaN");
  18.         System.out.println("content of name after setting  "+name);
  19.    
  20.     }
  21. }
  22. class thread2 implements Runnable
  23. {
  24.     Thread t;
  25.     thread2(String n){
  26.  t=new Thread(this,n);
  27. t.start();
  28.     }
  29. public void run()
  30.     {
  31.     String frnd[]={"rohit","rohini","aanchal","ojas","chinmoy"};
  32.     LinkedList fr=new LinkedList();
  33.    
  34.     for(int i=0;i<5;i++)
  35.     {
  36.         fr.add(i, frnd[i]);
  37.     }
  38.     System.out.println("content of frnds "+fr);
  39.    
  40.     for(int i=0;i<5;i++)
  41.     {
  42.         System.out.println(fr.get(i)+" removed");
  43.         fr.remove(i);
  44.  
  45.     }
  46.     //try{
  47.     System.out.println("content of frnds after removing "+fr);
  48.     /*}catch(Exception e)
  49.     {
  50.         System.out.println("No content in fr linkedlist if you want to see how this gives error just comment try&catch");
  51.     }*/
  52.  
  53.     }
  54. }
  55. public class linkedlist {
  56.  
  57.     public static void main(String argv[])
  58.     {
  59. new thread1("name");
  60. new thread2("frnds");
  61.        
  62.     }
  63.    
  64. }
Advertisement
Add Comment
Please, Sign In to add comment