Solucao aceita
wldomiciano 13 de set. de 2017
Uma sugestão:
class Valores {
int valorA ;
int valorB ;
Valores ( int a , int b ) {
valorA = a ;
valorB = b ;
}
}
/* ... */
Valores [] valores = new Valores [ 10 ] ;
valores [ 0 ] = new Valores ( 15 , 2548 ):
raphaeloneves 13 de set. de 2017 1 like
Outra forma seria usar um array bidimencional.
int [][] a = new int [ 10 ][ 10 ] ;
a [ 0 ][ 0 ] = 1 ;
a [ 0 ][ 1 ] = 2 ;
a [ 0 ][ n - 10 ] = n ...
Pantrol 21 de out. de 2020
vc criou um vetor com classes! e possível fazer o mesmo com métodos?
wldomiciano 21 de out. de 2020 1 like
Daria pra fazer algo parecido usando uma interface funcional e method references assim:
public class Main {
private static interface MyMethod {
void doSomething ();
}
public static void main ( String ... args ) {
MyMethod [] methods = new MyMethod [ 3 ] ;
methods [ 0 ] = Main :: methodA ;
methods [ 1 ] = Main :: methodB ;
methods [ 2 ] = Main :: methodC ;
for ( MyMethod method : methods )
method . doSomething ();
}
private static void methodA () {
System . out . println ( "methodA" );
}
private static void methodB () {
System . out . println ( "methodB" );
}
private static void methodC () {
System . out . println ( "methodC" );
}
}
Pantrol 21 de out. de 2020 1 like