Java String Join invertPhoneNumber(String storedNumber, String joinString)

Here you can find the source of invertPhoneNumber(String storedNumber, String joinString)

Description

invert Phone Number

License

Open Source License

Declaration

public static String invertPhoneNumber(String storedNumber, String joinString) 

Method Source Code


//package com.java2s;
//License from project: Open Source License 

import java.util.*;

public class Main {
    public static String invertPhoneNumber(String storedNumber, String joinString) {

        String prefix = String.join("", Arrays.asList("0", storedNumber.substring(2, 4)));
        String midnumbers, finalnumbers;

        try {//from   ww  w . j  av a  2s  .c  o  m
            midnumbers = storedNumber.substring(4, 7);
            finalnumbers = storedNumber.substring(7, 11);
        } catch (Exception e) { // in case the string doesn't have enough digits ...
            midnumbers = storedNumber.substring(4);
            finalnumbers = "";
        }
        return String.join(joinString, Arrays.asList(prefix, midnumbers, finalnumbers));

    }

    public static String invertPhoneNumber(String storedNumber) {
        return invertPhoneNumber(storedNumber, "");
    }
}

Related

  1. Join(ArrayList list, String delimiter)
  2. join(boolean endSlash, Collection paths)
  3. join(Collection collection, String separator)
  4. join(Collection items, String delimiter)