TOKYO, May 25 (Reuters) - Japan's Nikkei share average rallied after a two-day skid, led higher by chip-related companies on earnings optimism and amid robust inflows from foreign investors.

Chip-testing equipment maker Advantest Corp soared 15.79%, leading semiconductor shares after a blockbuster earnings forecast by Nvidia Corp in the U.S. Rakuten Group Inc climbed 1.54% after the online retailer priced a new share offering to fund its mobile expansion.

The Nikkei recovered from an early drop to advance 0.54% to 30,848.07, as of the midday break. Earlier this week, the index touched 31,352.53, the highest since August 1990. The broad Topix was flat at 2,152.00.

Japanese stocks have outperformed other major markets of late amid strong corporate earnings, increased chip investment, and optimism for a consumer sector tailwind as the country reopens from the pandemic. Foreign investors bought a net 867.5 billion yen ($6.42 billion) of Japanese shares in the week through May 20, rising from 808.9 billion yen the week before, Finance Ministry data showed. "Foreign investors are buying Japanese equities instead of U.S. equities because economic conditions are not good in the U.S. due to the banking problems, financial tightening, and the debt ceiling issue," said Masayuki Kubota, chief strategist at Rakuten Securities. "But in Japan, as the country reopens, the service sector is looking very strong now."

"Manufacturing, and in particular the semiconductor industry, is picking up," he added.

Advantest was set for its steepest climb since July 2019. Chip-equipment maker Tokyo Electron Ltd jumped 2.55%.

There were 158 decliners on the Nikkei versus 59 that gained ground. Financial and real estate shares were the biggest drags on the gauge.

Among decliners in the broader market, Riberesute Corp plunged 10% after the real estate developer said its president was arrested on Wednesday on suspicion of violating moneylending regulations.

(Reporting by Rocky Swift in Tokyo; Editing by Sonia Cheema)