How could autogenerate chain type code?

1

I have the doubt on how to generate auto-generate chain codes with a counter

that is:

e001 e002 e003 e004 ...

the following code is generating e000 e000 e000 e000

If someone could help me, it would be great, thanks

public class alumnoMemory implements ICrudService<alumno>
{
    List<alumno> alumnos = new ArrayList<>();
    
    static int cont;
    static String conte;
    
    static
    {
        cont = 0;
        conte="e00" + cont;
        
    }
    @Override
    public void create(alumno obj) {
        cont++;
        obj.setId(conte);
        alumnos.add(obj);
    }
}
    
    
asked by Innuendo 18.08.2018 в 05:12
source

1 answer

0

You only have to add it after obtaining the number, that is:

conte="e00" + cont;

that puts it in the create function after cont++; .

public class alumnoMemory implements ICrudService<alumno>
{
   List<alumno> alumnos = new ArrayList<>();
   static int cont;
   static String conte;
   static 
   { 
      cont = 0;
   }
   @Override
   public void create(alumno obj)
   {
      cont++;
      conte="e00" + cont;
      obj.setId(conte);
      alumnos.add(obj);
   }
}
    
answered by 18.08.2018 / 05:44
source