我有一个数组列表wilth值
ArrayList<String> HexValues = new ArrayList<String>();
HexValues.add("a");
HexValues.add("b");
HexValues.add("f");
HexValues.add("1");
HexValues.add("4");
HexValues.add("0");
HexValues.add("31");
HexValues.add("32");
HexValues.add("37");
System.out.println("The content of HexValues is: " + HexValues);
int start = HexValues.lastIndexOf("f");
if (start != -1) {
List<String> HexValuesEnd = HexValues.subList(start, HexValues.size());
System.out.println("The content of HexValuesEnd before leaving is: " + HexValuesEnd);
if (HexValuesEnd.size() > 0) {
HexValuesEnd.remove(1);
HexValuesEnd.remove(2);
HexValuesEnd.remove(3);
System.out.println("The content of HexValuesEnd after removing values at indexes 1 ,2,3: " + HexValuesEnd);
}
}
Run Code Online (Sandbox Code Playgroud)
输出是
The content of HexValues is: [a, b, f, …Run Code Online (Sandbox Code Playgroud) 我正在尝试创建代码以将wav文件放入数组列表,然后让arraylist播放文件.为什么这段代码不起作用?谢谢.
public class trackList {
public void tracklist(){
ArrayList<String> songs = new ArrayList();
songs.add("c:\\01.wav");
songs.add("c:\\02.wav");
byte[] buffer = new byte[4096];
for(int x = 0; x < songs.size(); x++){
try{
AudioInputStream ais = AudioSystem.getAudioInputStream(songs(x));
AudioFormat format = ais.getFormat();
SourceDataLine line = AudioSystem.getSourceDataLine(format);
line.open(format);
line.start();
while (ais.available() > 0) {
int len = ais.read(buffer);
line.write(buffer, 0, len);
}
line.drain();
line.close();
}
catch (Exception e) {
e.printStackTrace();
}
}
}
}
Run Code Online (Sandbox Code Playgroud) 无法弄清楚如何从扩展类中对arrayList进行排序......
继承人我所拥有的:
地址簿类:
import java.util.ArrayList;
import java.util.Iterator;
public class AddressBook
{
private ArrayList<Entry> data;
public AddressBook()
{
this.data = new ArrayList();
}
public String add(Entry paramEntry)
{
//Some code }
public ArrayList<Entry> getAddressBook()
{
return this.data;
}
public String getAll()
{
//Some code
}
}
Run Code Online (Sandbox Code Playgroud)
ExtendedAddressBook类:
import java.util.*;
import java.lang.Comparable;
public class ExtendedAddressBook extends AddressBook
{
public ExtendedAddressBook()
{
}
public String getAll()
{
String listAll = "Address Book\n";
ArrayList<Entry> allEntries = getAddressBook();
Collections.sort(allEntries);
for ( Entry entry : allEntries …Run Code Online (Sandbox Code Playgroud) 为什么会这样?
List<String> list = new ArrayList<String>();
list.add("aaa");
String s = list.get(0);
list.remove(0);
System.out.println(s);
Run Code Online (Sandbox Code Playgroud)
控制台说: aaa
有人可以帮我解释一下吗?我认为控制台应该是null,它应该是吗?
当我尝试添加人时,我仍然有问题.该代码被认为是检测无效的名称和生日,并且不会将此人添加到personList中.但是,因为在代码读取之前我无法获得生日,所以只能在循环结束时添加person对象.当我尝试测试添加一个invlid人名和/或生日时,会出现问题.表明:
无法添加人员:名称无效!!
新纪录:
姓名:null"
生日:未知的DOB
已被添加!
Exception in thread "main" java.lang.NullPointerException
at Instruction.readInstruction(Instruction.java:272)
at EPB.main(EPB.java:12)
else if(words[0].equalsIgnoreCase("add"))
{
Person p = new Person();
String s1 = line.substring(words[0].length()).trim();
String[] s2 = s1.split(";");
if(s2.length>=2)// s2[0] = " name Testing Three" s2[1] = " birthday 13-05-1981" and s2[2]=" address.."
{
for(int i=0; i<s2.length;i++)
{
String s3 = s2[i].trim(); // "delete the leading space" s2[0] = "name Testing Three" s2[1] = "birthday 13-05-1981"
String[] s4 = s3.split("\\s+"); //s4[0] = name; s4[1] = Testing; s4[2]=Three …Run Code Online (Sandbox Code Playgroud) 我有:
ArrayList<Integer> onlyOne = new ArrayList<Integer>();
onlyOne.add(Integer.valueOf(3));
ArrayList<Integer> two = new ArrayList<Integer>();
two.add(Integer.valueOf(3));
two.add(Integer.valueOf(4));
boolean check = two.contains(onlyOne);
Run Code Online (Sandbox Code Playgroud)
但这总是返回假,为什么?
可以有人解释我,为什么我在尝试setAdapter时有java.lang.NullPointerException?
当我尝试设置适配器时,我的arraylist已经填满了.我做错了什么?
谢谢!
activity_view_list.xml
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical">
<ListView
android:id="@+id/lvView"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_weight="1">
</ListView>
</LinearLayout>
Run Code Online (Sandbox Code Playgroud)
item.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="horizontal">
<ImageView
android:id="@+id/ivImage"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="@drawable/ic_launcher">
</ImageView>
<LinearLayout
android:id="@+id/linearLayout1"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_marginLeft="5dp"
android:layout_weight="1"
android:orientation="vertical">
<TextView
android:id="@+id/tvDescr"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="5dp"
android:text=""
android:textSize="20sp">
</TextView>
</LinearLayout>
</LinearLayout>
Run Code Online (Sandbox Code Playgroud)
我的产品类
package com.shvedchenko.skleroshop;
/**
* Created by dima on 14.08.13.
*/
public class Product {
String name;
int image;
Product(String _describe, int _image) {
name = _describe;
image = _image;
}
} …Run Code Online (Sandbox Code Playgroud) 我的代码在使用ArrayList包含对象的测试时工作,但在arrayList空时发出以下错误:
java.lang.IndexOutOfBoundsException: Index: 0, Size: 0
Run Code Online (Sandbox Code Playgroud)
我错了什么?
获取Rectangle具有最小区域的返回具有最小区域的矩形或者null如果没有矩形.
import java.util.ArrayList;
public class RectangleList
{
ArrayList<Rectangle> list = new ArrayList<Rectangle>();
public RectangleList(ArrayList<Rectangle> theList)
{
list = theList;
}
/**
* Gets the Rectangle with the smallest area
*
* @return the rectangle with the smallest area or null if there are no
* rectangles
*
*/
public Rectangle smallestArea()
{
Rectangle currentsmallestRectangle = list.get(0);
for (int i = 0; i < list.size(); i++) …Run Code Online (Sandbox Code Playgroud) 我试图在ArrayList对象中排序日期.为此,我使用sort其中dateList是我的ArrayList对象:
Collections.sort(dateList, new DateComparator());
Run Code Online (Sandbox Code Playgroud)
我尝试使用以下Comparator类执行此操作:
class DateComparator implements Comparator {
int compare(Object a, Object b) {
Date x = (Date) a;
Date y = (Date) b;
if (x > y) {
return 1;}
else if (x == y) {
return 0;}
else if (x < y) {
return 1;
}
}
}
Run Code Online (Sandbox Code Playgroud)
但是,这给了我以下错误:
1)无法实现比较(T,T) - 尝试分配较弱的访问权限; 是公共的,其中T扩展Object在接口Comparator中声明
2)二元运算符'>'的坏操作数类型:if(x> y){first type:Date second type:Date
3)二元运算符'<'的坏操作数类型:else if(x
什么是错的任何想法?
干杯