class Word(var mDefultTranslation: String, var mArabicTranslation: String ) {
fun Word (defultTranslation : String , arabicTranslation : String ){
mDefultTranslation = defultTranslation
mArabicTranslation = arabicTranslation
}
}
val words = arrayListOf<Word>()
words.add( Word("one","two" ))
val wordAdapter = WordAdapter (this, word??)
Run Code Online (Sandbox Code Playgroud) 所以这里我有一个数字数组,我只想更改特定索引的值。
ArrayList <Integer> numbers = new ArrayList <> ();
numbers.add(5);
numbers.add(10);
numbers.add(20);
Run Code Online (Sandbox Code Playgroud)
我试图做一些事情,比如
索引应该在userNumbers.get(1 (* 3));哪里1,我将该索引中的值乘以 3,因此结果是30因为10是第一个索引。尝试搜索,但我没有运气!
实际上,我正在从 RecyclerAdapter 在 ArrayList 中添加对象,并且我已经编写了一个用于在适配器中获取数组列表的函数。并且我正在从 MainActivity 中的该函数获取数组列表。但是每当我尝试将该数组列表从 MainActivity 传递到 Fragment 时它给出了 NullPointer(Null 值)。
帮我。
package com.example.codingmounrtain.addtocartbadgecount.adapter;
import android.content.Context;
import android.support.v7.widget.RecyclerView;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.Button;
import android.widget.ImageView;
import android.widget.TextView;
import com.example.codingmounrtain.addtocartbadgecount.activity.MainActivity;
import com.example.codingmounrtain.addtocartbadgecount.ModelClasses.Movie;
import com.example.codingmounrtain.addtocartbadgecount.R;
import com.example.codingmounrtain.addtocartbadgecount.interfaces.AddorRemoveCallbacks;
import com.squareup.picasso.Picasso;
import java.util.ArrayList;
public class RecyclerAdapter extends RecyclerView.Adapter<RecyclerAdapter.MyViewHolder> {
ArrayList<Movie> cartmovies = new ArrayList<>();
public interface Listener {
void onSelectMovie(int position);
}
Context context;
private final ArrayList<Movie> movies;
private final Listener listener;
public RecyclerAdapter(Context context, ArrayList<Movie> movies,Listener …Run Code Online (Sandbox Code Playgroud) 我有一个包含 Arraylist 的类ArrayList<Move> moves。我从另一个类调用该 Arraylist 的 getter 并添加一个 move: panel.getMoves().add(move)。但是当我之后遍历 Arraylist 时,发生了一些非常奇怪的错误,暗示没有正确添加移动。
我必须打电话panel.setMoves(panel.getMoves().add(move))吗?如果是这样,为什么我一直认为列表是可变的?
It kinda speaks for itself but how do I fill this?
Map<Integer,ArrayList<Integer>>intMap = new HashMap<Integer, ArrayList<Integer>>();
Run Code Online (Sandbox Code Playgroud)
I've already tried
intMap.put(1, 2);
intMap.put(1, 3); etc
Run Code Online (Sandbox Code Playgroud)
and
intMap.put(1, (2, 3);
Run Code Online (Sandbox Code Playgroud) 我有一个ArrayList<String>定期添加的。我想要做的是将整个 ArrayList 转换为 aString而不进行循环。谁能告诉我可以不使用循环吗?
编辑:所以我们找到了一些解决方案,比如
list.stream().collect(Collectors.joining());
Run Code Online (Sandbox Code Playgroud)
或者
String result = String.join(",", list);
Run Code Online (Sandbox Code Playgroud)
或其他一些。现在只是为了获取知识,我提出了一个问题,哪种方式是编译器的最佳方式?
我正在尝试使用 toArray() 将 ArrayList 转换为 Array,但它返回一个 object[] 而不是 double[]。见下文:
double [] arr = arrList.toArray(new Double[arrList.size()]);
Run Code Online (Sandbox Code Playgroud)
我收到不兼容的类型错误。
这是 arrList 包含的内容:
I/System.out: [0.0, 2.455430030822754, 1.834529995918274, 0.7368429899215698, -0.5264459848403931, -1.5101100206375122, -1.8526500463485718, -1.6131700277328491, -0.9388419985771179, 0.053711701184511185, 0.35541099309921265, -0.18560799956321716, -0.884518027305603, -1.4304900169372559, -1.5486400127410889, -0.943471014499, 0.0]
Run Code Online (Sandbox Code Playgroud)
这是它的获得方式:
private void rec(SensorEvent event) {
double x = event.values[0];
arrList.add(x);
}
Run Code Online (Sandbox Code Playgroud)
我试过不调整数组大小(即使用 new Double[0]),虽然我认为这不是问题,但这也不起作用。
我在网上寻找了类似的问题,我发现的都是字符串示例,我认为 Double 可能是问题所在?不太确定。
在这方面很新,所以很抱歉,如果很明显。
如果某些内部列表属性值不满足条件,如何从列表中删除元素。这里的技巧是该属性本身是一个列表,比较基于该内部列表的某些属性。请参考以下示例并帮助填写代码中的注释部分:
目的 :
Class product{
private String productId;
private String productName;
private List<Attribute> attributeList;
public static class Attribute{
private Long attributeId;
}
}
Run Code Online (Sandbox Code Playgroud)
驱动程序类:
Class Driver{
List<product> productList = new ArrayList<product>();
/*
Remove the object from productList if attributeList doesn't contain attribute with attributeId = x;
*/
}
Run Code Online (Sandbox Code Playgroud) 我正在努力理解为什么 ArrayList 中的 addAll() 方法不起作用。我有我的课:
public class XList<E> extends ArrayList<E> {...
}
Run Code Online (Sandbox Code Playgroud)
用一个方法:
public XList<E> union(XList<E> input) {
System.out.println(this);//
System.out.println(input);
this.addAll(input);
return this;
}
Run Code Online (Sandbox Code Playgroud)
System.out.println 表示,正确的值在给定的列表中,但添加后,“this”不会更新,并且未经修改就返回。你能告诉我问题的根源吗?非常感谢任何帮助。
SSCCE:
public class Main {
public static void main(String[] args) {
XList<Integer> list1 = new XList<>(1, 3, 9, 11);
XList<Integer> list2 = XList.of(5, 6, 9);
List<Integer> m1 = list1.union(list2);
System.out.println(m1);
}
}
class XList<E> extends ArrayList<E> {
private List<E> lista;
public XList(E a, E b, E c) {
lista = new ArrayList<>();
lista.add(a);
lista.add(b); …Run Code Online (Sandbox Code Playgroud) 我定义了以下变量
$A = New-Object -TypeName "System.Collections.ArrayList"
Run Code Online (Sandbox Code Playgroud)
现在我n向它添加元素:
$A.Add(1..n)
Run Code Online (Sandbox Code Playgroud)
现在我想将每个元素分成$A几p部分k(如果 ,最后一个可能有较少的元素p*k>$A.count)。我怎么做?
arraylist ×10
java ×8
collections ×3
android ×2
arrays ×1
hashmap ×1
immutability ×1
java-8 ×1
kotlin ×1
netbeans ×1
powershell ×1
remove-if ×1
string ×1
toarray ×1