regionMatches

2 respostas
edymrex

Bem eu gostaria de sabe pra que serve esse método…?, no livro da deitel fala que ele serve para comparar parte de duas String mas não é isto que ele está fazendo exemplo:

public class testes2 
{
     public static void main(String args[])
     {
    	 String w="abcdefghijlmn";
    	 String y="1";
    	 
    	 if(w.regionMatches(0, w, 0, w.length()))
    	 {
    		 System.out.print("existe");
    	 }
    	 else
    	 {
    		 System.out.println("não existe");
    	 }
     }
}

pra min ele compara partes de duas Strings verificando se são iguais cetro, mais não é isto que ele está faazendo conforme o código que eu mostrei é isto mesmo…?

2 Respostas

Luca

Olá

javadoc:
public boolean regionMatches(int toffset,
String other,
int ooffset,
int len)

Tests if two string regions are equal.

A substring of this String object is compared to a substring of the argument other. The result is true if these substrings represent identical character sequences. The substring of this String object to be compared begins at index toffset and has length len. The substring of other to be compared begins at index ooffset and has length len. The result is false if and only if at least one of the following is true:

    * toffset is negative.
    * ooffset is negative.
    * toffset+len is greater than the length of this String object.
    * ooffset+len is greater than the length of the other argument.
    * There is some nonnegative integer k less than len such that: this.charAt(toffset+k) != other.charAt(ooffset+k) 

Parameters:
    toffset - the starting offset of the subregion in this string.
    other - the string argument.
    ooffset - the starting offset of the subregion in the string argument.
    len - the number of characters to compare. 
Returns:
    true if the specified subregion of this string exactly matches the specified subregion of the string argument; false otherwise.</blockquote>

O exemplo dentro do if testa se w é igual a w

A instrução if (w.regionMatches(0, w, 0, w.length())) está assim mesmo no livro?

[]s
Luca

edymrex

No cara entendi pelo documento que vc me passo esse livro da deitel é uma bosta exiplica pelos coco valew cara

Criado 13 de junho de 2007
Ultima resposta 13 de jun. de 2007
Respostas 2
Participantes 2