12.07.2015 Views

k19-k11-orientacao-a.. - Departamento de Sistemas e Computação

k19-k11-orientacao-a.. - Departamento de Sistemas e Computação

k19-k11-orientacao-a.. - Departamento de Sistemas e Computação

SHOW MORE
SHOW LESS
  • No tags were found...

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

STRING 1441 String texto = "K11 ,K12 ,K21 ,K22 , K23 ";23 String [] cursos = texto . split (",");45 // imprime K116 System . out . println ( cursos [0]) ;78 // imprime K129 System . out . println ( cursos [1]) ;1011 // imprime K2112 System . out . println ( cursos [2]) ;1314 // imprime K2215 System . out . println ( cursos [3]) ;1617 // imprime K2318 System . out . println ( cursos [4]) ;Código Java 16.11: split()replaceAll()O método replaceAll() cria uma cópia <strong>de</strong> uma string substituindo “pedaços” internos por outroconteúdo.1 String texto = " Curso <strong>de</strong> Java da K19 , Curso <strong>de</strong> JSF da K19 ";23 String textoAlterado = texto . replaceAll (" Curso "," Treinamento ");45 // imprime Treinamento <strong>de</strong> Java da K19 , Treinamento <strong>de</strong> JSF da K196 System . out . println ( textoAlterado );Código Java 16.12: replaceAll()Exercícios <strong>de</strong> Fixação1 Crie um projeto no eclipse chamado String.2 Crie uma classe para testar o Pool <strong>de</strong> Strings e a comparação com “==” e com equals().1 public class TestaPoolDeStrings {23 public static void main ( String [] args ) {4 String nome1 = " Rafael Cosentino ";5 String nome2 = " Rafael Cosentino ";67 // imprime true8 System . out . println ( nome1 == nome2 );9 // imprime true10 System . out . println ( nome1 . equals ( nome2 ));1112 String nome3 = new String (" Rafael Cosentino ");13 String nome4 = new String (" Rafael Cosentino ");1415 // imprime false16 System . out . println ( nome3 == nome4 );17 // imprime true18 System . out . println ( nome3 . equals ( nome4 ));144 www.<strong>k19</strong>.com.br

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!