我必须在内存中保留数千个字符串,以便在Java中以串行方式访问.我应该将它们存储在数组中还是应该使用某种List?
由于数组将所有数据保存在连续的内存块中(与Lists不同),使用数组存储数千个字符串会导致问题吗?
可能重复:
如何向String []数组添加新元素?
我是Java的新手,所以我需要一些帮助
我有
String [] scripts = new String [] ("test3","test4","test5");
Run Code Online (Sandbox Code Playgroud)
我想为这个数组(脚本)添加新的字符串(string1,string2)作为示例
String string1= " test1"
String string2 = "test2"
Run Code Online (Sandbox Code Playgroud)
我想在init中添加新字符串,但是在后期阶段
我怎么能这样做?
想要向现有阵列添加或附加元素
int[] series = {4,2};
Run Code Online (Sandbox Code Playgroud)
现在我想用我发送的新值动态更新系列..
就像我发送3个更新系列一样 int[] series = {4,2,3};
再次,如果我发送4更新系列为 int[] series = {4,2,3,4};
再次,如果我发送1更新系列,int[] series = {4,2,3,4,1};如此
怎么做????
我在其他一些函数中每5分钟生成一个整数,并希望发送更新int[] series数组..
可能重复:
如何向String []数组添加新元素?
如何将新项添加到String数组中?我正在尝试将项添加到最初为空的String.示例:
String a [];
a.add("kk" );
a.add("pp");
Run Code Online (Sandbox Code Playgroud) 我是Java的初学者,我正在尝试创建一个自定义类的数组.假设我有一个名为car的课程,我想创建一个名为Garage的汽车阵列.如何将每辆车添加到车库?这就是我所拥有的:
car redCar = new Car("Red");
car Garage [] = new Car [100];
Garage[0] = redCar;
Run Code Online (Sandbox Code Playgroud) 我想添加从android的文本视图到现有数组列表的值.我当前的数组列表包含值Cricket,Football和文本视图我想在最后位置添加数组列表中的曲棍球..然后我的数组列表变成Cricket ,足球,曲棍球.我的板球和足球阵列来自之前的活动.但现在它只添加板球和足球,但不添加曲棍球我该怎么办?
resultArrGame+=resultArrGame.add(txtGame.getText().toString());
Run Code Online (Sandbox Code Playgroud) 首先,让我向您展示到目前为止的代码:
public void populateArray(){
//NOTE: THIS METHOD SHOULD BE RUN FIRST. Many of the methods in this class rely on a populated file array to function.
// This method will populate our file array.
// First, we note the directory we want to pull files from.
File folder = new File("HR");
File dir = new File("");
File file = new File("");
//Then we fill an array with the list of documents in that directory
//This will also include folders.
int …Run Code Online (Sandbox Code Playgroud) 我有内容解析器查询的以下代码:
String selection = Columns.NAME + "=? and " + Columns.AVAILABILITY + "=?";
String[] selectionArgs = { name, true };
Cursor c = getContentResolver().query(Columns.URI, null, selection, selectionArgs, null);
Run Code Online (Sandbox Code Playgroud)
这段代码工作正常,因为我只有一个名字,但现在我有一个名字数组,只有当它们的可用性为真时才会被添加到游标中.即,我的场景是我想将这些行放在游标中,只有当它们的可用性为真时才有任何名称(存在于数组中).
我怎样才能做到这一点?