Player's inventory look for item [duplicate]

I did not see the pocket edition tag when I gave this answer. This answer will not work for pocket edition. These commands are for Java Edition 1.12.2

Here is a command to check all player's inventories for a diamond:

testfor @a {Inventory:[{id:"minecraft:diamond"}]}

You can change minecraft:diamond to other items/blocks.

If you need to test for a specific amount, you can add count to the command:

testfor @a {Inventory:[{id:"minecraft:diamond",Count:64b}]}

This tests for a full stack of 64.

Those commands will go positive if a player has the item(s) but is not very useful otherwise. You can also add a scoreboard tag to the player who has the item(s). This allows you to target the players that have the item in other commands:

scoreboard players tag @a add Holding {Inventory:[{id:"minecraft:diamond",Count:64b}]}

Then you can use that tag within the target selector of another command. As an example, lets make everyone who has the diamonds say hello:

/execute @a[tag=Holding] ~ ~ ~ say hello