Virgula

1 resposta
S

Boas, eu tenho os seguintes métodos e tenho um output com uma vírgula a mais no fim, e não sei como resolver isso… alguém me pode ajudar ?

Output

public String vertexToEdge(){
		Iterator it = edges.listIterator();
		String s ="";
		String s1="";
		while(it.hasNext()){
			WeightedEdge we= (WeightedEdge) it.next();
			s1 = we.toString()+",";
		}
		return s += s1 ;

	}
public String toString() {
		String aux="";
		String st="";
		for (int i = 0; i < vertices.size(); ++i) {
			Vertex v = vertices.elementAt(i);
			aux = v.vertexToEdge();
			st+=aux;
		}
		return "["+st+ "]";
	}

1 Resposta

E

opa boa noite

você por um acaso tentou algo assim:

public String vertexToEdge(){
      Iterator it = edges.listIterator();
      String s ="";
      String s1="";
      while(it.hasNext()){
         WeightedEdge we= (WeightedEdge) it.next();
         if( it.hasNext() ) {
             s1 = we.toString()+",";
         }
      }
      return s += s1 ;

   }

onde irá incluir a virgula apenas se o mesmo tiver
um próximo, faz um teste :wink:

abraços

Criado 13 de maio de 2006
Ultima resposta 13 de mai. de 2006
Respostas 1
Participantes 2