Bonjour,
J'ai une petite question, je cherche à améliorer mon code java,
J'ai une String qui est composée de sous chaines de 4caractères, qui sont séparées par un vide.
et je veux alimenter des string d'un objet :
Genre :

Code : Sélectionner tout - Visualiser dans une fenêtre à part
String s = YYAA AAAA BBBB CCCC DDDD EE
donc ce que je fais moi est :
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
String[] tabString = s.split(" ");
 
		if( tabString == null ){
			return;
		}
 
		this.setIString2(tabString[1]);
		if( tabString.length >= 3 ){
			this.setIString3(tabString[2]);
		}
		if( tabString.length >= 4 ){
			this.setIString4(tabString[3]);
		}
		if( tabString.length >= 5 ){
			this.setIString5(tabString[4]);
		}
		if( tabString.length >= 6 ){
			this.setIString6(tabString[5]);
		}
		if( tabString.length >= 7 ){
			this.setIString7(tabString[6]);
		}
		if( tabString.length >= 8 ){
			this.setIString8(tabString[7]);
		}
		if( tabString.length >= 9 ){
			this.setIString9(tabString[8]);
		}
 
 
	}
Donc je me demandais, s'il n'y avait pas mieux que ce code ?
Merci