Welcome to my blog!

The companion workshop to Andy's new book 'Transcending CSS - The Fine Art of Web Design', this session will lift the lid on web technologies including XHTML, CSS and DOM scripting and show you exactly where tey fit in with modern web design. Andy will reveal the benefits of working with meaningful XHTML markup, he will help you look...

kadinho Rss

Converter Char [] to String

Posted by kadinho | Posted in Java | Posted on 06-10-2010

Olá,

Já existem vários métodos de converter um array de caracteres do tipo char[]  pela Internet fora, mas como estou sempre a aprender resolvi criar o meu e partilhar.

nota: Um array de caracteres do tipo char[] vem por exemplo de um campo do tipo password em Swing.

aqui fica:

public String getPasswordString() {
String str = new String();
for(int i=0;i<=this.password.length-1;i++){
str += Character.toString(password[i]);
}
return str;
}

Simples, basicamente criamos uma nova String e criamos um ciclo para percorrer todo o array e dentro do ciclo vamos acrescentando os caracteres a nossa String.

ads
ads
ads
ads
  • Social Slider