getAll() method can be used.
1. Create a Custom Metadata Type.
2. Create few records.
Sample Code:
Map < String, Test__mdt > mapCustomMetadataType = Test__mdt.getAll();
for ( String strKey : mapCustomMetadataType.keySet() ) {
system.debug( 'Key is ' + strKey );
system.debug( 'Custom Metadata Type record is ' + mapCustomMetadataType.get( strKey ) );
}
Output: