Comma Constant in Internal Library

I want to use constant char/string comma (,) in my code.

Where I can find static final variable in standard library? If there is not such a place, can you point me popular external library for that?

EDIT: I don't want to create my own constant, I want to use it from JDK (or external library if it not exists)

2

3 Answers

What would be the benefit of depending on an external library for just a constant? If your not using code from that library I would advise to define the constant in your own project.

If you use the comma-constant all over the place in your code try to find a common interface/class and define the constant in that interface/class.

If there is no common interface/class create an enum with a logical name. Do not create a class or interface just for wrapping a constant.

If you need the comma-constant in a single class declare it in that class. (either protected or private).

See also What is the best way to implement constants in Java?

But if you really want to use a third-party library, you might want to look at:

2

Did you mean this :

public final char CH = ',';
1

You can use this:

import sun.tools.java.Constants;

Constants.opNames[Constants.COMMA]
1

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Maya Lin-Takahashi

Maya Lin-Takahashi

Consumer Tech & Gadget Reviewer

Maya is a hardware enthusiast who tests and reviews smart home devices, smartphones, wearables, and audio gear. She focuses on practical consumer value and build quality.

Share this article
Twitter Facebook Pinterest