String SomeLongString=javapimethodfor(String[]strings,String delimeter)

String SomeLongString=javapimethodfor(String[]strings,String delimeter),java,string,implode,Java,String,Implode,或者这也可以奏效: String SomeLongString = JavaAPIMethodFor (String[] strings, String delimiter); 我想把字符串连接成一个更大的字符串,但这根本没用。我知道我可以使用Arrays.toString(Object someString)将所有数据附加到字符串中,然后调整字符串,删除不需要的字符。但这不是真正有效的,建造一些东西,只是为了重建它。因此,在字符串[]中循环并在每个元素之间添加我的字符可能是一种方法: Str

或者这也可以奏效:

String SomeLongString = JavaAPIMethodFor (String[] strings, String delimiter);
我想把字符串连接成一个更大的字符串,但这根本没用。我知道我可以使用Arrays.toString(Object someString)将所有数据附加到字符串中,然后调整字符串,删除不需要的字符。但这不是真正有效的,建造一些东西,只是为了重建它。因此,在字符串[]中循环并在每个元素之间添加我的字符可能是一种方法:

String SomeLongString = JavaAPIMethodConvertingArrayWithDelimeter (String[] strings, char delimiter)
import static org.junit.Assert.*;
导入org.junit.Test;
公共类除名{
私有字符串分隔符字符串(字符串[]测试,字符串分隔符){
StringBuilder结果=新建StringBuilder();
int计数器=0;
如果(测试长度>计数器){
结果.追加(测试[计数器++);
while(计数器<测试长度){
result.append(分隔符);
结果.追加(测试[计数器++);
}
}
返回result.toString();
}
@试验
公开无效测试(){
字符串[]测试=新字符串[]
{“猫”、“狗”、“老鼠”、“汽车”、“卡车”、“杯子”、“我不知道”、“什么都有!”;
字符串分隔符=“|…”;
assertEquals(“分隔符字符串格式错误”,
“猫、狗、老鼠、汽车、卡车”
+“|……|杯子|……|我不知道|……|什么都不知道!”,
分隔符字符串(测试,分隔符));
}
}
我想要的是在使用标记器后将字符串组合在一起。我放弃了这个想法,因为它可能比它的价值更麻烦。我选择从较大的字符串中寻址子字符串,我在“应答”中包含了该子字符串的代码


我要问的是——java API是否有与delimitedString函数等效的函数?有几个人的答案似乎是否定的。

据我所知,没有内置的方法。您可以做的是获取它的子字符串:

import static org.junit.Assert.*;

import org.junit.Test;

public class DelimetedString {


    private String delimitedString(String [] test, String delimiter){
        StringBuilder result = new StringBuilder();
        int counter = 0;
        if(test.length > counter){
           result.append(test[counter++]);
           while(counter < test.length){
              result.append(delimiter);
              result.append(test[counter++]);
           }
        }
        return result.toString();
    }

    @Test
    public void test() {
        String [] test = new String[] 
{"cat","dog","mice","cars","trucks","cups","I don't know", "anything!"};
        String delimiter = " |...| ";
        assertEquals("DelimitedString misformed",
        "cat |...| dog |...| mice |...| cars |...| trucks "
            +"|...| cups |...| I don't know |...| anything!",
        delimitedString(test, delimiter));
    }

}

这是一节我最后一起上的课。我想将一个文本文件分解成块,然后使用行号通过Servlet发送这些块以获得相关数据。这是一个在我家服务器上运行的应用程序,它允许我在不同的设备上读取文本文件,并保留与文件相关的元数据

String str = Arrays.toString(arrayHere);
str = str.substring(1, str.lenght() - 1);

我不确定问题是什么。你想要一个不存在的标准JDK API函数吗?我只是使用Commons'
StringUtils.join
来实现这一点。我不相信有一个内置的API方法来实现您所寻找的,但是一个
StringBuilder
和一个for循环将快速完成操作。可能的重复
package net.stevenpeterson.bookreaderlib;

public class SplitStringUtility {

private String subject;

public SplitStringUtility(String subject) {
    this.subject = subject;
}

public String getRow(int rowAddress, int charsPerRow) {
    String result = "";
    if (rowAddress >= 0 && charsPerRow > 0) {
        int startOfSubString = rowAddress * charsPerRow;
        int endOfSubString = startOfSubString + charsPerRow;
        result = getSubString(startOfSubString, endOfSubString);
    }
    return result;
}

private String getSubString(int startOfSubString, int endOfSubString) {
    String result = "";
    if (startOfSubString <= subject.length()) {
        if (endOfSubString <= subject.length()) {
            result = subject.substring(startOfSubString, endOfSubString);
        } else {
            result = subject.substring(startOfSubString);
        }
    }
    return result;
}

}
package net.stevenpeterson.bookreaderlib;

import static org.junit.Assert.*;

import net.stevenpeterson.bookreaderlib.SplitStringUtility;

import org.junit.Test;

public class SplitStringUtilityTest {

    public final String empty = "";
    public final String single ="a";
    public final String twoChars = "ab";
    public final String threeChars = "abc";
    public final String manyChars = "abcdefghijklmnopqrstuvwxyz";

    private SplitStringUtility splitter;

    @Test
    public void splitTestsEmpty() {
        makeSplitter(empty);
        assertEquals("We are trying to get a non-existant string",
            "", 
            splitter.getRow(3,4));
    }


    @Test
    public void splitTestsNegativeRowOrColumn() {
        makeSplitter(manyChars);
        assertEquals("We are trying to get a non-existant string",
            "",
            splitter.getRow(-3,4));

        assertEquals("We are trying to get a non-existant string",
            "", 
            splitter.getRow(-1,-1));

        assertEquals("We are trying to get a non-existant string",
            "", 
            splitter.getRow(1,-1));
    }



    @Test
    public void splitTestsSingleCharacterStrings() {
        makeSplitter(single);

        assertEquals("split the string consisting of 1 character",
            "a",
            splitter.getRow(0,1));

        assertEquals("split the string consisting of 1 character, " +
                "but ask for two characters, " +
                "the string containing only a single char " +
                "should be returned","a", splitter.getRow(0,2));

    }

    @Test
    public void splitTestsTwoChars() {
        makeSplitter(twoChars);
        assertEquals("Row #0 of the ab string in 1 column rows",
            "a", 
            splitter.getRow(0,1));

        assertEquals("Row #1 of the ab string in 1 column rows",
            "b",
            splitter.getRow(1,1));

        assertEquals("Row #0 of the ab string in 2 column rows",
            "ab",
            splitter.getRow(0,2));

        assertEquals("Row #1 of the ab string in 4 column rows " 
            +"should return a blank string",
            "",
            splitter.getRow(1,4));

        assertEquals("Row #0 of the ab string in 4 column rows " 
            +"should return the ab string",
            twoChars, 
            splitter.getRow(0,4));

    }


    @Test
    public void splitTestsManyChars() {
        //split the alphabet into rows of 4 characters, return row 3
        //Expect "mnop"
        makeSplitter(manyChars);
        assertEquals("Row #3 of the alphabet in 4 column rows",
            "mnop",
            splitter.getRow(3,4));

        assertEquals("Row #0 of the alphabet in 4 column rows",
            "abcd", 
            splitter.getRow(0,4));

        assertEquals("Row #0 of the alphabet in 26 column rows",
            manyChars, 
            splitter.getRow(0,26));

        assertEquals("Row #0 of the alphabet in 26 column rows",
            "z",
            splitter.getRow(1,25));

        assertEquals("Row #0 of the alphabet in 27 column rows" 
            + " since the alphabet has 26 characters "
            + "it would be nice to get what we have", manyChars,
           splitter.getRow(0,27));
    }


    private void makeSplitter(String subject){
        splitter = new SplitStringUtility(subject);
    }


}