skip to Main Content

I am trying to convert the "Black" to string but I am not getting it

colorList.add(new ColorView("Black", "#000000"));

2

Answers


  1. Not sure of your expectations here. But if you need to use the color black as color in your code you can directly use it like below:

    String color = "Black";
    

    There’s no need to convert.

    Login or Signup to reply.
  2. If you want to convert any RGB color to hexadecimal value,then your can try below code snippet

    Color yourColor = new Color(0,0,0);
    String hex = "#" + Integer.toHexString(yourColor.getRGB()).substring(2);
    

    If you just want to convert some specified color,then Color has many built in color constant, we can try below code snippet

    String hex = "#" + Integer.toHexString(Color.BLACK.getRGB()).substring(2);
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search