Sample Code:
String a = '0013h00000SIc6uAAD';
Id i = Id.valueOf( a );
here String ‘a’ should be a valid record id. We cannot generate Salesforce Id using this method because Salesforce Id is system generated Id and it cannot be generated by us.