Sei sulla pagina 1di 8

import java.io.

BufferedReader;

import java.io.File;

import java.io.FileReader;

import java.io.FileWriter;

import java.util.ArrayList;

import java.util.Collections;

//INPUT

Scanner in = new Scanner(System.in);

...

in.close();

String rc= in.nextLine();

Int rc= in.nextInt();

//OUTPUT

System.out.println("...");

//SPLIT

rigaS =line1.split(" ");

//LETTURA FILE

try{

BufferedReader br= new BufferedReader(new FileReader ("file.txt"));

String line;

while((line=br.readLine())!=null){

...

}br.close();
}catch (Exception e){

e.printStackTrace();

//SCRITTURA FILE

try{

PrintWriter out=new PrintWriter(new FileWriter(new File("1.txt")));

...

out.close();

}catch (Exception e){

e.printStackTrace();

//METODI

-METODO REGISTRO

public class Registro {

private HashMap<String,Studente> studenti;

private HashMap<String, ArrayList<Esame>> carriere;

public Registro ()

this.studenti = new HashMap<>();

this.carriere = new HashMap<>();

public void aggiungiStudente(String nome, String cognome)

Studente s = new Studente(nome,cognome);

this.studenti.put(s.getMatricola(),s);

this.carriere.put(s.getMatricola(),new ArrayList<>());

}
-MAIN

Registro r = new Registro();

String[] nomeCognome;

System.out.println("\tNome e Cognome separati da spazio: ");

nomeCognome=in.nextLine().split(" ");

r.aggiungiStudente(nomeCognome[0].trim(),nomeCognome[1].trim());

//STRINGHE

String stringa = ("Ciao a tutti, mi chiamo Stefano");

System.out.println("length = "+stringa.length());

String sub = stringa.substring(4, 7);

System.out.println("starts with 'ciao': "+stringa.startsWith("Ciao"));

System.out.println("ends with 'ciao': "+stringa.endsWith("Ciao"));

System.out.println("equals 'ciao': "+ciao.equals("ciao"));

System.out.println("equals ignore case 'ciao': "+ ciao.equalsIgnoreCase("ciao"));

System.out.println("contains 'Ste': "+stringa.contains("Ste"));

System.out.println("index of 'Ste': "+stringa.indexOf("Ste"));

//STRING BUILDER

StringBuilder builder = new StringBuilder();

builder.append("Ciao");

builder.append("Stefano");

System.out.println(builder.toString());

builder.insert(0,"Ehi ");

//ARRAYLIIST (TIPI PARAMETRICI)

ArrayList <String> s = new ArrayList <String>();

for (int i=0; i<NOME.size(); i++)


System.out.println(NOME.get(i)); stampa

String [] NOME_ARRAY = NOME_ARRAYLIST.toArray(new String[] {});

s.add("ciao");

s.add(2,"ciao"); //aggiunge

s.set(2,"ciao"); //sostituisce

s.contains("ciao");

s.remove (2); //rimuove

s.remove("ciao");

s.removeAll(z); //elimina tutti gli elementi di z

s.retainAll(z); //tiene tutti gli elementi di z

s.clear();

s.get(i).equals(z); //controlla se uguali

s.isEmpty(); //verifica se vuota (boolean)

Collections.sort(s);

for(int i=0; i<s.size(); i++)

out.println(s.get(i));

equalsIgnoreCase
messaggi[] m= new messaggi[100];

for (int i=0; i<100; i++)

m[i]= new messaggi();

//HASHMAP

HashMap<Integer,String> numeri=new HashMap<>();

numeri.put(0, "zero");

for(Integer i : numeri.keySet())

System.out.println(i+" -> "+numeri.get(i));

System.out.println("size = "+ numeri.size());

System.out.println("contains 3: "+numeri.containsKey(3));

System.out.println("is empty: "+numeri.isEmpty());

numeri.remove(1);

System.out.println("contains uno: "+ numeri.containsValue("uno"));

numeri.replace(0, "o");

//MATRICI

int [][] a = new int [rows][cols];


for(int i=0; i<a.length; i++)

for (int j=0; j<a[0].length; j++)

a[i][j]=rand.nextInt(10);

for(int i=0; i<a.length; i++)

for (int j=0; j<a[0].length; j++)

System.out.printf("%01d ", a[i][j]);

System.out.println();

//CALCOLO LUNGHEZZA VETTORE

Math.sqrt(Math.pow(p[i].lati[1],2)+Math.pow(p[i].lati[2],2))

//NUMERI RANDOM

import java.util.Random;

Random rand = new Random();

//SWITCH CASE

switch (VARIABILE)

case 1:

...
break;

case 2:

...

break;

...

default:

...

break;

//DO WHILE

do

...

}while (CONDIZIONE);

//FOR E

for(String s: parti)

...

//TIME

import java.time.LocalDate;

LocalDate data=LocalDate.now();

data=LocalDate.of(1987, Month.MARCH, 12);

LocalTime tempo= LocalTime.now();

tempo= LocalTime.of(1, 2);

tempo=LocalTime.NOON;
tempo=LocalTime.MIDNIGHT;

LocalDateTime tempoEdata= LocalDateTime.now();

tempoEdata = LocalDateTime.of(data,tempo);

System.out.println(tempoEdata.getHour());

System.out.println(tempoEdata.getMonth());

System.out.println(tempoEdata.isAfter(LocalDateTime.now()));

System.out.println(tempoEdata.plusDays(5));

System.out.println(data.getDayOfWeek());

Potrebbero piacerti anche