473,805 Members | 1,882 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

something like C-language printf function

13 New Member
Can somebody show me, how to declare function with variable number of parameters in Java? I want to provide method similar to C-language printf function.

Thanks in adavne!

M.
Dec 18 '06 #1
3 1600
r035198x
13,262 MVP
Can somebody show me, how to declare function with variable number of parameters in Java? I want to provide method similar to C-language printf function.

Thanks in adavne!

M.
This is only available from java 5.0 upwards



Expand|Select|Wrap|Line Numbers
  1.  
  2. import static java.lang.System.out;
  3. public class VargArgs {
  4.  public static void main(String ... args) { //Can even use them here
  5.   myPrintf("one");
  6.   myPrintf("one", "two");
  7.  } 
  8.  public static void myPrintf(String ... args) {
  9.   for(String s : args) {
  10.    out.println(s);
  11.   }
  12.  }
  13. }
  14.  
  15.  
Dec 18 '06 #2
kenk
13 New Member
Thanks again for your answer.

King Regards

M.
Dec 18 '06 #3
r035198x
13,262 MVP
Thanks again for your answer.

King Regards

M.
Sorry I don't remember giving you help around here. Have we met before?
Dec 18 '06 #4

Sign in to post your reply or Sign up for a free account.

Similar topics

3
5999
by: Martin Lucas-Smith | last post by:
I am trying to take a string and split it into a filename and a number where the number is what follows the *last* instance of a comma in that string. Split and explode won't work because if the filename part of the original string contains a , then I end up with too many parts. if (!preg_match ('/^(.*),(+)$/', $string, $matches)) {throwError ();} also fails, because the first part of the regular expression becomes greedy if there is...
8
2233
by: Sam Sungshik Kong | last post by:
Hello! I use Python for ASP programming. I found something weird. Response.Write(Request("something")) It draws "None" when there's no value for something. Actually I expect "" instead of "None". So I changed it like
5
1940
by: Daniel Vukadinovic | last post by:
Can anyone explain me these things in C++? 1.What is :: used for like in the next case: if(.... { ... ::one;
4
1553
by: D.Hering | last post by:
When I see something like this prototype: SOMETHING int func( int x ); what is SOMETHING doing there? thanks very much, -Dieter
2
2879
by: Andrew Backer | last post by:
I hope someone out there can help me with this, because I am stuck. My problem is that I have an instance of a generic class, but I don't know ahead of time what the type parameter used was. In my case the type must derive from a class, like UserControl, so I at least know I should be able to use that. I can not figure out a way to get this as an instance of the generic class, but with the base class as the type parameter. I am...
0
9716
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9596
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10360
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
7646
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6876
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5542
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5677
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4323
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
3845
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.