Salve a tutti, sto creando un semplice programmino che rilevi i conti in economia azienda in partita doppia, per una tesina sulla programmazione del 5 anno di superiore. per semplificare il lavoro in esposizione ho creato una JTextField che con colpi di invio ricerca nella JList che contiene un bel po di nomi dei conti, tutti quei conti che iniziano con la stessa stringa esempio:
se scrivo nella textfield s: avrò come input
Socio c/conferimenti
socio c/prelevamenti ecc.... tutto bene fin quì
il problema e se scrivo più parole, se scrivo so avrò come input:
socio ....
socio....
ma anche
fondo conto......
il fatto è che tiene in considerazione solo la 2 cifra ignorando la s
posto il codice vediamo se potete aiutarmi, ho cercato qualche codice simile su internet senza ottenere risultato:
codice:
package Codice;
import java.util.ArrayList;
public class FiltraggioStringa {
ArrayList <String>al = new ArrayList<String>();
String array[];
public void filtra(String items[], String s){ //ARRAY, E IL FILTRO DELLA LISTA
array = items;
al = new ArrayList<String>();
char a, b; //SERVONO A TRASFORMARE LE LETTERE IN CORSIVO IN MODO CHE LE POSSO CONFRONTARE
int c = 0, i = 0; //CONTATORI NEI CICLI
int s1, s2, s3 = 0; //DIMENSIONI DELLE STRINGHE
ConfrontoCaratteri cc = new ConfrontoCaratteri(); //UNA CLASSE CHE TRASFORMA LE STRINGHE IN CORSIVO
while(true){
for (c = 0; c < array.length; c++){
s1 = items[c].length();
s2 = s.length();
if (s1 >= s2)
s3 = s2;
else
s3 = s1;
if (s3 >= i){ //S3 SARA' LA LUNGHEZZA PIU' PICCOLA DELLE STRINGHE IN MODO CHE i NON ESCE FUORI DAL RANGE DI UNA DELLE 2
a = items[c].charAt(i); a = cc.ritornoCarattere(a);
b = s.charAt(i); b = cc.ritornoCarattere(b);//LE CHAR DIVENTANO IN CORSIVO
if (a == b)
al.add(items[c]);
}
}
array = new String[al.size()];
for(int t = 0; t < array.length; t ++){
array[t] = al.get(t);
}//PONGO L'ARRAY LIST AD ARRAY, COSI' IL 2 ELEMENTO LO RICERCHERA' TRA QUELLI POSITIVI ALLA 1 RICERCA
al = new ArrayList<String>();// E RIAZZERO LA L'ARRAY LIST
i++;
if (s3 == i)
break;
}
}
public String[] ritornaLista(){
return array;//DA QUI PRENDO I RISULTATI E LI AGGIUNGO ALLA LISTA
}
}