I have this C# static function below that takes a MatchCollection, an input string and a pattern to search for. The MathCollection is passed by reference so that to use it I don't have to run a match twice. I can use it thusly:
      MatchCollection matches = new MatcchCollection();
      string pattern = "foo";
      string input = "foobar";
      if (tryRegMatch(matches, input, pattern) { //do something here}
 public static boolean tryRegMatch(out MatchCollection match, string input, string pattern)
    {   
        match = Regex.Matches(input, pattern);
        return (match.Count > 0);
    }
The question is whether it is possible to do this in Java I have read several articles that state Java is pass by value (keeping it simple). By default C# is, but you can use the 'out' modifier to make it pass by reference. I am doing a lot of matching, and this would make the coding simpler, otherwise I have to run the match then test it separately for success.
 
    