Advertisement
fabi2295

Untitled

Nov 22nd, 2016
96
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.63 KB | None | 0 0
  1. import java.util.ArrayList;
  2.   import java.util.List;
  3.    
  4.    
  5.   public class MyGenericApp {
  6.    
  7.          public static void main(String[] args){            
  8.                
  9.                //Sem Generics
  10.                List lista = new ArrayList();
  11.                lista.add(1);
  12.                lista.add(2);
  13.                lista.add(3);
  14.                
  15.                int total = 0;
  16.                for (int i = 0; i < lista.size(); i++){
  17.                       total += (int) lista.get(i); //fazendo casting
  18.                }
  19.                
  20.                System.out.println(total);
  21.                
  22.          }
  23.          
  24.   }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement