• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Char to Integer

 
Ranch Hand
Posts: 48
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi
Am try to convert a Char Char A = 'F'; to an Integer without Changing 'F' to a numeric value. Then Set it at something like list.set(4, A). Is this possible?
 
Bartender
Posts: 2236
63
IntelliJ IDE Firefox Browser Spring Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Molayo Decker wrote:Hi
Am try to convert a Char Char A = 'F'; to an Integer without Changing 'F' to a numeric value. Then Set it at something like list.set(4, A). Is this possible?


What do you mean by this? An integer IS a numerical value. By the way, so is char.
 
Molayo Decker
Ranch Hand
Posts: 48
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Am writing a code to replace all numbers in an array that are divisible by another number to be replaced by F or B

So if 3 is divisible by 3 replace 3 in the array {1,2,F,4,5,6,7}. Am trying to set 3 to F by using the set method but it only takes two integers or two strings. set (int, String)
 
Ranch Hand
Posts: 2412
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
You mean the terms array and list. If you're using java.util.List, what type of object are you storing in it?
 
Molayo Decker
Ranch Hand
Posts: 48
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I am storing numbers in my ArrayList

 
Marshal
Posts: 79177
377
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Molayo Decker wrote:. . .

Ouch! What dreadful variable names. Try
myList.set(0, (int)'F');
If you have a List<Integer>, you can put ints into it and they will undergo boxing conversion. You cannot (I think) put chars directly because they cannot undergo widening (=cast to int) and boxing conversion together. If you cast it to an int, then you only need boxing conversion and that can be done automatically.
 
Paweł Baczyński
Bartender
Posts: 2236
63
IntelliJ IDE Firefox Browser Spring Java Linux
  • Likes 2
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
What about
myList.set(0, +'F');
instead of
myList.set(0, (int)'F');

I have never seen + operator used in such way.
I don't know if the confusion is worth saving few keystrokes.

What do you think?
 
Campbell Ritchie
Marshal
Posts: 79177
377
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Now that is a first. I have never seen a possible use for the unary plus operator but I think you have got one there. Well done Paweł.
 
Bartender
Posts: 2911
150
Google Web Toolkit Eclipse IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Paweł Baczyński wrote:
I have never seen + operator used in such way.



+1 For creativity
 
Campbell Ritchie
Marshal
Posts: 79177
377
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Since this isn't the “beginning” forum, at least we can be confident that everybody reading it knows what the unary plus operator does.

Can't we???‍???
 
Java Cowboy
Posts: 16084
88
Android Scala IntelliJ IDE Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Note that a character such as 'F' is not an Integer, so you cannot store it in a list that can only hold Integer objects.
 
Sheriff
Posts: 5555
326
IntelliJ IDE Python Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

salvin francis wrote:+1 For creativity


49 for creativity .... .... +'1' .... get it? .... get it?

I'll get my coat.
 
Don't get me started about those stupid light bulbs.
reply
    Bookmark Topic Watch Topic
  • New Topic