0

Which inbuilt java classes other than String uses pooling? For example we have String which uses pooling,what are the other inbuit java classes that uses pooling?

2 Answers2

2

The Integer has a pool with a pool with all the values between -128 and 127.

If you do:

Integer x = 127;
Integer y = 127;
System.out.println(x == y);

you'd get true as an output, but if you change that to:

Integer x = 128;
Integer y = 128;
System.out.println(x == y);

then you'd get false, as 128 is not part of the pool and x and y actually represent two different objects.

More info:

Konstantin Yovkov
  • 62,134
  • 8
  • 100
  • 147
  • 3
    [Between *at least* -128 and 127](https://docs.oracle.com/javase/8/docs/api/java/lang/Integer.html#valueOf-int-), and you can configure the JVM to cache values outside this range too. – Andy Turner Aug 14 '19 at 11:32
0

am not sure if it fits the bill, java.net.InetAddress uses dns resolution (domain to ip translation) cache. it actually has two caches - for positive as well as negative lookups.

Sharon Ben Asher
  • 13,849
  • 5
  • 33
  • 47