Advertisement
alexarcan

Functie cu nr variabil de elemente

Jan 9th, 2015
420
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.51 KB | None | 0 0
  1. import java.util.ArrayList;
  2.  
  3.  
  4. public class MyElementsTree {
  5.     private ArrayList<String> lista = new ArrayList<String>(3);
  6.    
  7.     public void add(String...elements){
  8.         for(String e : elements)
  9.             lista.add(e);
  10.     }
  11.    
  12.     public String toString(){
  13.         return lista.toString();
  14.     }
  15.    
  16.     public static void main(String[] args){
  17.         MyElementsTree m1 = new MyElementsTree();
  18.         m1.add("Ana"); m1.add(" are "); m1.add(" un hotel ");
  19.         m1.add(" o vila", " si ", "o casa de vacanta la mare");
  20.         System.out.println(m1);
  21.        
  22.        
  23.     }
  24. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement