Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9093065
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 16, 20262026-06-16T22:59:40+00:00 2026-06-16T22:59:40+00:00

I have a void method which is supposed to take a String and split

  • 0

I have a void method which is supposed to take a String and split it into two strings based on a delimiter. Having used the debugger the method seems to be working correctly, but the two empty strings I pass in for the method to store the results don’t seem to be getting updated. I must be doing something idiotic here but any help is appreciated!

public static void main(String[] args) {
    String dictFile = "/Users/simonrhillary/Desktop/Dictionary(3).txt";
    String synFile = "/Users/simonrhillary/Desktop/Synonyms(2).txt";
    fileReader dictFR = new fileReader();
    fileReader synFR = new fileReader();
    dictFR.filePath = dictFile;
    synFR.filePath = synFile;
    dictFR.openFile(dictFile);
    synFR.openFile(synFile);
    String[] dictionary = dictFR.fileToArray();
    String[] synonyms = synFR.fileToArray();
    String regx = "^[aflmptu]+$";
    String regexTemplate = "^[]+$";
    String word1 = "";
    String word2 = "";
    synToWords(synFR.getLine(3), word1, word2);//error seems to be here. 
                                                       //word1 and word 2 stay ""
    System.out.println(word1 +" " + word2);
    printArray(findCombos(dictionary, word1, word2));

}

public static void synToWords(String syn, String wordI, String wordII){
    String[] words = syn.split("\\t");
    wordI = wordI + words[0];
    wordII = wordII + words[1];
}

there are other methods I haven’t posted but they are all working fine. It’s just the synToWords method thats the problem. Many Thanks!

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-16T22:59:41+00:00Added an answer on June 16, 2026 at 10:59 pm

    Java passes references by value. So this line:

    wordI = wordI + words[0];
    

    assigns a new String to wordI but it is only the local (within the method) copy of the reference which changes. The original word1 variable still refers to the original String.

    To make it work, you could use an array instead:

    public static void synToWords(String syn, String[] word1And2){
        String[] words = syn.split("\\t");
        word1And2[0] = word1And2[0] + words[0];
        word1And2[1] = word1And2[1] + words[1];
    }
    

    and in your main code:

    String[] words = { "", "" };
    synToWords(synFR.getLine(3), words);
    System.out.println(words[0] +" " + words[1]);
    

    Or you could simply return a array of String:

    public static String[] synToWords(String syn){
        String[] words = syn.split("\\t");
        return new String[] {words[0], words[1]};
    }
    
    String[] words = synToWords(synFR.getLine(3));
    System.out.println(words[0] +" " + words[1]);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a method which I would like to invoke asynchronously: void Foo() {
I have this recursive method which deletes empty folders: private void DeleteEmpty(DirectoryInfo directory) {
I have a method on a WCF proxy which returns void. If the return
I have this method which supposed to get a buffer and write some content
I have a -(void) method in my main UITableView class, which I use to
Assume I have two methods @Secured(ROLE_ADMIN) @RequestMapping(value = /methodA, method = RequestMethod.GET) public void
Imagine I have a method: void Method(bool parameter){ if(parameter){ // first case } else
I have a method -(void)myMethod:(MyObject*)obj And I am detaching a new thread [NSThread detachNewThreadSelector:@selector(myMethod)
I currently have this method: -(void)seperateGuides { DLog(GetGuideListCount: %i, [[appDelegate getGuideList] count]); columnOneArray =
I have a UISearchbar with delegate method - (void)searchBar:(UISearchBar *)searchBar textDidChange:(NSString *)searchText { if(searchText.length>3){

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.