1

I know about CharBag bag = CharAdapter.adapt("hello world!").toBag();it's nice, but it's not linked. I need bag with linked input string and how can i get keys and values from this collection to make output like:

h 1
e 1
l 3
o 2
  1
w 1
r 1
d 1
! 1
Deepstack
  • 96
  • 8

1 Answers1

1

There is currently no LinkedCharBag in Eclipse Collections as you point out. You can accomplish your goal by using the following solution leveraging distinct on CharAdapter:

CharAdapter helloWorld = Strings.asChars("hello world!");
CharBag bag = helloWorld.toBag();
helloWorld.distinct().forEach(c -> System.out.println(c + " " + bag.occurrencesOf(c)));
Donald Raab
  • 6,458
  • 2
  • 36
  • 44