Advertisement
ChocoMan

Untitled

Jun 10th, 2012
330
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.28 KB | None | 0 0
  1. import java.util.ArrayList;
  2.  
  3.  
  4. public class StringT {
  5.  
  6.    
  7.     public static void main(String[] args) {
  8.        
  9.         // alpha would represent fetchContactNames()
  10.         ArrayList<String> alpha = new ArrayList<String>();
  11.         // bravo would represent fetchContactNumbers()
  12.         ArrayList<String> bravo = new ArrayList<String>();
  13.         // charlie would represent newList
  14.         ArrayList<String> charlie = new ArrayList<String>();
  15.        
  16.         alpha.add("One");    bravo.add("1"); charlie.add("5");
  17.         alpha.add("Two");    bravo.add("2"); charlie.add("2");
  18.         alpha.add("Three");  bravo.add("3"); charlie.add("7");
  19.         alpha.add("Four");   bravo.add("4"); charlie.add("3");
  20.         alpha.add("Five");   bravo.add("5");
  21.         alpha.add("Six");    bravo.add("6");
  22.         alpha.add("Seven");  bravo.add("7");
  23.        
  24.         // this will print charlie just as you see above
  25.         for(int i = 0; i < charlie.size(); i ++){
  26.             System.out.println(charlie.get(i));
  27.         }
  28.        
  29.         System.out.println("---------------------");
  30.        
  31.         // this will print charlie with the numbers replaced as names
  32.         for(int i = 0; i < charlie.size(); i++){
  33.             int index = bravo.indexOf(charlie.get(i));
  34.             if(bravo.contains(charlie.get(i))){
  35.                 charlie.set(i, alpha.get(index));
  36.             }
  37.         }
  38.        
  39.         for(int i = 0; i < charlie.size(); i ++){
  40.             System.out.println(charlie.get(i));
  41.         }
  42.     }
  43. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement