Java:elementAt(int) is undefined for the type

Résolu
domxaline Messages postés 204 Statut Membre -  
 domxaline -
Bonjour,
import java.util.Vector;
public class DupValue 
{
	public static void main(String[]args)
	{
		String tmpVector;
		Vector  v=new Vector();
		v.add("Delhi");
		v.add("Mumbai");
		v.add("Calcutta");
		v.add("Chennai");
		v.add("Delhi");
		Vector tempVector=new Vector();
		String tmpValue;
		for(int j=0; j<=v.size();j++)
		{
			tmpValue=(String)v.elementAt(j);
			if(tmpValue!=null)
			{
				if(tmpVector.isEmpty())
					tmpVector.addElement(tmpValue);
				if (tmpVector.indexOf(tmpValue==-1))
					tmpVector.addElement(tmpValue);
			}
		}
		for(int j=0; j<tmpVector.size(); j++)
		{
			System.out.print(tmpVector.elementAt(j));
		}
	}
}


en compilant mon prg,ce dernier m'afficher une erreur de message
Exception in thread "main" java.lang.Error: Unresolved compilation problems:
The method addElement(String) is undefined for the type String
Incompatible operand types String and int
The method addElement(String) is undefined for the type String
The method size() is undefined for the type String
The method elementAt(int) is undefined for the type String

at DupValue.main(DupValue.java:21)

la ligne 21 est
tmpVector.addElement(tmpValue);

aidez moi svp
A voir également:

2 réponses

domxaline Messages postés 204 Statut Membre 10
 
quand j'ecrit comme suivant:
for(int j=0; j<=v.size();j++) 
  { 
   tmpValue=(String)v.elementAt(j); 
   if(tmpValue!=null) 
   { 
    if(tmpVector.isEmpty())     
     tmpVector.addElement(tmpValue); 

    if (tmpVector.indexOf(tmpValue==-1)) 
     tmpVector.addElement(tmpValue); 
   } 
  } 
  for(int j=0; j<tmpVector.size(); j++) 
  { 
   System.out.print(tmpVector.elementAt(j)); 
  } 

Exception in thread "main" java.lang.Error: Unresolved compilation problems:
The method addElement(String) is undefined for the type String
Incompatible operand types String and int
The method addElement(String) is undefined for the type String
The method size() is undefined for the type String
The method elementAt(int) is undefined for the type String

at DupValue.main(DupValue.java:21)


la ligne 21 est
tmpVector(int).addElement(tmpValue);


aidez moi svp
1
domxaline
 
j'ai résolu mon problème
import java.util.Vector;
public class DupValue 
{
	public static void main(String[]args)
	{
		Vector  v=new Vector();
		v.add("Delhi");
		v.add("Mumbai");
		v.add("Calcutta");
		v.add("Chennai");
		v.add("Delhi");
		Vector tmpVector=new Vector();
		String tmpValue;
		for(int j=0; j<v.size();j++)
		{
			tmpValue=(String)v.elementAt(j);
			if(tmpValue!=null)
			{
				if(tmpVector.isEmpty())
				{
					tmpVector.addElement(tmpValue);
				}
				if (tmpVector.indexOf(tmpValue)==-1)
				{
					tmpVector.addElement(tmpValue);
				}
			}
		}
		for(int j=0; j<tmpVector.size(); j++)
		{
			System.out.print(tmpVector.elementAt(j)+",");
		}
	}
}


merci d'avance
0