BOSTON (AP) _ Danny and the Juniors must have had the gift of prophecy when they recorded ''Rock and Roll Is Here to Stay'' 30 years ago.

The number of radio stations nationwide playing rock music of the late 1950s, the 1960s and 1970s has doubled in the last five years, and the trend is continuing, according to the authoritative Broadcasting/Cableca sting Yearbook.

For 1981, the yearbook listed 232 AM or FM radio stations playing the gamut of popular music of past decades: ''oldies, golden oldies, nostalgia, classic rock, old gold, solid gold, and classic rock.''

That number had grown to 464 by 1986, and members of the yearbook staff at the main office of Broadcasting magazine in Washington said recently the 1988 yearbook will list 537 of the country's 10,219 stations as playing oldies.

There are indications most are doing well in a highly competitive business.

Figures at Arbitron Ratings, the service that keeps tabs on the nation's listening habits, show that in many large markets oldies stations are among the top 10 draws.

There is no clear-cut explanation for classic rock's popularity, but many in the industry believe millions of baby boomers prefer the music they grew up with.

''I think it really comes down to the music,'' said WODS program director Dave VanDyke, whose Boston station went on air last October with its ''oldies'' format. ''For the adults of today, the music that's being released just doesn't do a thing for them, but teen-agers (also) are desiring this kind of music more than what's being recorded today.''

In New York, Joe McCoy, program director at WCBS-FM, said his station's ''oldie'' format transcended the generations.

''This is the stuff parents grew up on, this is the stuff they were weaned on, so they're translating it to the kids today,'' he said in a telephone interview.

In Hartford, Conn., where WDRC-FM plays ''solid gold rock 'n' roll'' with emphasis on music between 1964-1975, the station's program director, Frank Holler, agreed the oldies had appeal for young adults.

But Holler, himself a baby boomer at 39, was most eloquent when describing the meaning of WDRC's music to others of his age.

He spoke on the telephone to a background of Peter and Gordon's ''World Without Love.''

''The people love it, it reminds them of a very special time of their lives,'' said Holler of his station's music. ''There is a familiarity that both men and women are immediately comfortable with, and it has not been played to such excess within the last 15 years as to be burned out.''

''I think as long as the baby boom generation is alive with disposable income that the advertisers are looking to reach, the music of the '50s, '60s and '70s is going to continue to be popular,'' he said.

Garry Guthrie, whose Edinborough Rand Inc. advises stations on formats, agreed that ''there is considerable advertiser interest'' in baby boomers.

''Most of them are in the $35,000-plus range,'' he said, in a telephone interview from Scottsdale, Ariz. ''You are giving ... (advertisers) a large block of people with discretionary income who want to be on top of trends, who are willing to buy durable goods.''

Guthrie said he has overseen about 12 station changes to classic rock formats since he set up business in October 1985, and ''we have yet to have any failures.''