Please note, this is a STATIC archive of website www.tutorialspoint.com from 11 May 2019, cach3.com does not collect or store any user information, there is no "phishing" involved.
Tutorialspoint

J8- Basics

import java.util.Date;
import java.util.List;
import java.util.ArrayList;

public class HelloWorld{

     public static void main(String []args)  throws  Exception{
        System.out.println("Hello World");
        
        
    
        Stock s = new Stock().setId("1").setCompanyName("Sapinet");
        s.setAmount(22.00).setPurchaseDate(new Date());
        
        List<Stock> list = new ArrayList<>();
        
        list.add(s);
        list.add(s.copy().setAmount(23.00));
        
        
        list.forEach(HelloWorld::printStock);
        
     }
     
     public static void printStock(Stock a){
         System.out.println(a.getId());
     }
     
     public static class Stock implements Cloneable {
         private String id;
         private String companyName;
         private Double amount;
         private Date purchaseDate;
         
         public Stock copy() throws CloneNotSupportedException{
             return (Stock) clone();
         }
         
         
         public Date getPurchaseDate(){
             return this.purchaseDate;
         }
         
         public Stock setPurchaseDate(Date d){
             this.purchaseDate = d;
             return this;
         }
         
         public String getId()   {
             return this.id;
         }
         
         public Stock setId(String id){
             this.id = id;
             return this;
         }
         
         public String getCompanyName(){
             return this.companyName;
         }
         
         public Stock setCompanyName(String name){
             this.companyName = name;
             return this;
         }
         
         public Double getAmount(){
             return this.amount;
         }
         
         public Stock setAmount(Double amount){
             this.amount = amount;
             return this;
         }
     }
}

Advertisements
Loading...

We use cookies to provide and improve our services. By using our site, you consent to our Cookies Policy.