Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8255559
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T01:33:57+00:00 2026-06-08T01:33:57+00:00

Why this does work OK?: String f = Mi name is %s %s.; System.out.println(String.format(f,

  • 0

Why this does work OK?:

String f = "Mi name is %s %s.";
System.out.println(String.format(f, "John", "Connor"));

And this doesnt?:

String f = "Mi name is %s %s.";
System.out.println(String.format(f, (Object)new String[]{"John","Connor"}));

If the method String.format takes a vararg Object?

It compiles OK but when I execute this the String.format() takes the vararg Object as a single an unique argument (the toString() value of the array itself), so it throws a MissingFormatArgumentException because it cannot match with the second string specifier (%s).

How can I make it work?
Thanks in advance, any help will be greatly appreciated.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-08T01:33:59+00:00Added an answer on June 8, 2026 at 1:33 am

    The problem is that after the cast to Object, the compiler doesn’t know that you’re passing an array. Try casting the second argument to (Object[]) instead of (Object).

    System.out.println(String.format(f, (Object[])new String[]{"John","Connor"}));
    

    Or just don’t use a cast at all:

    System.out.println(String.format(f, new String[]{"John","Connor"}));
    

    although that might generate a compiler warning. (See this answer for a little more info.)

    The cleanest, I think, would be to avoid a String[] in the first place:

    System.out.println(String.format(f, new Object[]{"John","Connor"}));
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Update: This does work, I was being stupid :( i have the following extension
This does NOT work: Sub X() Dim A As Access.Application Set A = CreateObject(Access.Application)
can anyone tell me why this does not work Excel.Worksheet ws_res = (Excel.Worksheet) wb.Worksheets.Add(mis,
Apparently, this does not work. WHY ??????? I don't want to do all this
Here is my code, this does not work in Chrome, Safari, FF or Opera.
Quick and silly jQuery selector question. Why this does not work : jsFiddle demo
How do I unbind hover in jQuery? This does not work: $(this).unbind('hover');
I am setting up embedded forms in my rails app. This does not work
<style type=text/css> #[':0:adId'] { /* this does not work */ background:red; } </style> <div
Does this work well as a Singleton in actionscript? i.e. are there any gotchas

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.