Getting the individual digits of a number Approach 1:

Repeated division-modulus operations:

long num = 123456789;
int count = 0;
while(num &gt; 0)
{
 int digit = num % 10;
 if(digit == 1)
  count ++;
 num /= 10;
}


Approach 2:

Convert it into an String and get the characters at the position:

long num = 123456789;
int count = 0;
String s = String.valueOf(num);
for(int i = 0; i &lt; s.length(); i++)
{
 char ch = s.charAt(i);
 if(ch == '1')
    count ++;
}


The second operation doesn't need to get the remainder and the quotient each time. A charAt() method can be enough.

Which approach is considered to be better and why?

Consider taking the input from the console.

1st Case:

long num = scanner.nextLong();


2nd Case:

String s = scanner.nextLine();


Here there would be no overhead on converting the number to string.

Also let us assume it is for positive numbers.
I would suggest a third approach that extends the conversion-to-string approach: conversion to List of Character 

The benefits of this is that you can utilise Java 8 collection stream feature to perform filtering, aggregation and other functions on the elements.

for instance, your example can be expressed as such (edited following @h.j.k's comment): 

    long num = 123456789;
    String s = String.valueOf(num);
    long count = s.chars()
            .mapToObj(i -&gt; (char)i)
            .filter(ch -&gt; ch.equals('1'))
            .count();