Searching in java/connected-components