The multinational said there was no indication that any data had been taken and was working with authorities to investigate the incident.
The California-based corporation said in a statement: "Apple has identified malware which infected a limited number of Mac systems through a vulnerability in the Java plug-in for browsers.
"The malware was employed in an attack against Apple and other companies, and was spread through a website for software developers. We identified a small number of systems within Apple that were infected and isolated them from our network.
"There is no evidence that any data left Apple."
It added that it was releasing an updated Java malware removal tool that would remove the malware from computers if found.